1

The code pastes the information into a new worksheet.

Whatever row it appears in the original is where it appears in the new worksheet.

How do I paste to the beginning of the new worksheet?

Sub CloverLeafLocal048488()
    Dim xRg As Range
    Dim XCell As Range
    Dim A As Long
    Dim B As Long
    A = Worksheets("OriginalDataPull").UsedRange.Rows.Count
    B = Worksheets("CloverLeafLocal-048488").UsedRange.Rows.Count
    If B = 1 Then
        If Application.WorksheetFunction.CountA(Worksheets("CloverLeafLocal-048488").UsedRange) = 0 Then B = 0
    End If
    Set xRg = Worksheets("OriginalDataPull").Range("X1:X" & A)
    On Error Resume Next
    Application.ScreenUpdating = False

    For X = 1 To xRg.Count
        If CStr(xRg(X).Value) = "048488" Then
            xRg(X).EntireRow.Copy Destination:=Worksheets("CloverLeafLocal-048488").Range("A" & X + 1)
            B = X + 1
        End If
    Next
    Application.ScreenUpdating = True

End Sub
Community
  • 1
  • 1
  • You are pasting it in `Range("A" & X + 1)` but note that `X` relates to the row number on your original sheet. You need to make a new variable that tracks the row on the paste sheet and replace that with `X` – urdearboy Dec 22 '20 at 22:27
  • You don't need to loop here at all. Just filter `Column X` for `048488` and then copy the visible cells and paste them all at once. There are **many** examples of how to do this on Stackoverflow. Here is just [one example](https://stackoverflow.com/a/17531969/6706419) – urdearboy Dec 22 '20 at 22:33

0 Answers0