0

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 Answer 1

2

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 
Sign up to request clarification or add additional context in comments.

1 Comment

+1 but would recommend changing Sheet2.Range("H1048576").End(xlUp).Row to code that uses Rows.Count to automatically find the last use cell in both xl03 (65536 rows) and xl07/10 (1048576 rows)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.