0
votes

I want to copy cell data from "Sheet2" to "Sheet1" if the value in column "H" on "Sheet2" is not equal to "0" (zero).

If the statement is true, I want to copy

  • "Sheet2:A2" to "Sheet1:A7",
  • "Sheet2:F2" to "Sheet1:C7",
  • "Sheet2:G2" to "Sheet1:E7", and
  • "Sheet2:H2" to "Sheet1:G7".

I then want to loop through the remaining rows on "Sheet2" and continue copying until the worksheet runs out of data.

1

1 Answers

2
votes

Use the following code

Sub filldata()
LastRow = Sheet2.Range("H1048576").End(xlUp).Row
i = 2
j = 7

For i = 2 To LastRow

If Sheet2.Range("H" & i).Value <> 0 Then 'the condition to check

Sheet1.Range("A" & j).Value = Sheet2.Range("A" & i).Value
Sheet1.Range("C" & j).Value = Sheet2.Range("F" & i).Value
Sheet1.Range("E" & j).Value = Sheet2.Range("G" & i).Value
Sheet1.Range("G" & j).Value = Sheet2.Range("H" & i).Value
j = j + 1

End If


Next

End Sub