0
Sub CopyRowBasedOnCellValue()

'Excel 10 Tutorial

    Dim xRg As Range

    Dim xCell As Range

    Dim A As Long

    Dim B As Long

    Dim C As Long

    A = Worksheets("Sheet1").UsedRange.Rows.Count

    B = Worksheets("Sheet2").UsedRange.Rows.Count

    If B = 1 Then

    If Application.WorksheetFunction.CountA(Worksheets("Sheet2").UsedRange) = 0 Then B = 0

    End If

    Set xRg = Worksheets("Sheet1").Range("C1:C" & A)

    On Error Resume Next

    Application.ScreenUpdating = False

    For C = 1 To xRg.Count

        If CStr(xRg(C).Value) = "Shipment OI" Then

            xRg(C).EntireRow.Copy Destination:=Worksheets("Sheet2").Range("A" & B + 1)

            B = B + 1

        End If

    Next

    Application.ScreenUpdating = True

End Sub

referrence code from Youtube tutorials not sure on how to change the destination of the data to be reflected on D2 as i have items to be placed on A2

[Data reflected in A2 onwards] 1

[Need Data to be reflected on D2 onwards] 2

Glenn G
  • 667
  • 10
  • 24
Rahman
  • 1
  • 2
  • How does this differ from your [previous question](https://stackoverflow.com/questions/69869419/) ? – CDP1802 Nov 07 '21 at 12:35
  • 1
    `xRg(C).EntireRow.Copy Destination:=Worksheets("Sheet2").Range("A" & B + 1)` is the output, so just change that to whatever you need, like `xRg(C).EntireRow.Copy Destination:=Worksheets("Sheet2").Range("D" & B + 1)`. Also both your pictures are the same? – Christofer Weber Nov 07 '21 at 16:50
  • Create a new `sub` and add this line of code: `MsgBox Worksheets("Sheet1").UsedRange.Address(0, 0)`. Run it and share the message box result (in the comments is ok). Also, do confirm if you want to copy the relevant data (rows where column `C` is `Shipment OI`) in `Sheet1` to `Sheet2` starting in column `D`? Is the code in the workbook where these two worksheets are located? – VBasic2008 Nov 08 '21 at 00:44

0 Answers0