Question: I have an Excel sheet with names as one column and their working hours as values in next column.

I want to copy names with values greater than 40 to new sheet without any blanks in columns. The new sheet should have both names and the working hours; any text in the values column should be ignored.

```
Sub CopyCells()
    Dim sh1 As Worksheet, sh2 As Worksheet 
    Dim j As Long, i As Long, lastrow1 As Long 

    Set sh1 = Worksheets("Sheet1") 
    Set sh2 = Worksheets("Sheet2") 
    lastrow1 = sh1.Cells(Rows.Count, "F").End(xlUp).Row 

    For i = 1 To lastrow1 
        If sh1.Cells(i, "F").Value > 20 Then 
            sh2.Range("A" & i).Value = sh1.Cells(i, "F").Value 
        End If 
    Next i 
End Sub

```

Answer: 
I would recommend using `AutoFilter` to copy and paste as it is faster than looping. See the example below.

**My Assumptions**

1. Original Data is in Sheet 1 as shown the snapshot below
2. You want the output in Sheet 2 as shown the snapshot below

**CODE**

I have commented the code so that you will not have a problem understanding it.

```
Option Explicit

Sub Sample()
    Dim wsI As Worksheet, wsO As Worksheet
    Dim lRow As Long

    '~~> Set the input sheet
    Set wsI = Sheets("Sheet1"): Set wsO = Sheets("Sheet2")

    '~~> Clear Sheet 2 for output
    wsO.Cells.ClearContents

    With wsI
        '~~> Remove any existing filter
        .AutoFilterMode = False

        '~~> Find last row in Sheet1
        lRow = .Range("A" & .Rows.Count).End(xlUp).Row

        '~~> Filter Col B for values > 40
        With .Range("A1:B" & lRow)
            .AutoFilter Field:=2, Criteria1:=">40"
            '~~> Copy the filtered range to Sheet2
            .SpecialCells(xlCellTypeVisible).Copy wsO.Range("A1")
        End With

        '~~> Remove any existing filter
        .AutoFilterMode = False
    End With

    '~~> Inform user
    MsgBox "Done"
End Sub

```

**SNAPSHOT**

![enter image description here](https://i.stack.imgur.com/yvYF1.png)
Try rhis

```
Sub CopyCells()
    Dim sh1 As Worksheet, sh2 As Worksheet
    Dim j As Long, i As Long, lastrow1 As Long
    Set sh1 = Worksheets("Sheet1")
    Set sh2 = Worksheets("Sheet2")
    lastrow1 = sh1.Cells(Rows.Count, "F").End(xlUp).Row
    j = 1
    For i = 1 To lastrow1
        If Val(sh1.Cells(i, "F").Value) > 20 Then
            sh2.Range("A" & j).Value = sh1.Cells(i, "F").Value
            j = j + 1
        End If
    Next i
End Sub

```