• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Referencing row start

IKHAN

Member
Hello,

How to modify below query to always start from Row 60 (sheet4) even if new row inserted above row 60?

Thanks for helping out...




Code:
Dim i As Long
Dim j As Long

Sheet4LastRow = Worksheets("Sheet4").Range("D" & Rows.Count).End(xlUp).Row
sheet5LastRow = Worksheets("Sheet5").Range("A" & Rows.Count).End(xlUp).Row

    For j = 1 To Sheet4LastRow
        For i = 1 To sheet5LastRow
            If Worksheets("sheet4").Cells(j, 4).Value = Worksheets("sheet5").Cells(i, 1).Value _
                And Worksheets("Sheet5").Cells(j, 5).Value = Worksheets("Sheet5").Cells(i, 2).Value Then
                Worksheets("Sheet4").Cells(j, 1).Value = Worksheets("Sheet5").Cells(i, 3).Value
                Worksheets("Sheet4").Cells(j, 3).Value = Worksheets("Sheet5").Cells(i, 4).Value
                Worksheets("Sheet4").Cells(j, 6).Value = Worksheets("Sheet5").Cells(i, 5).Value
                Worksheets("Sheet4").Cells(j, 7).Value = Worksheets("Sheet5").Cells(i, 6).Value
                Worksheets("Sheet4").Cells(j, 8).Value = Worksheets("Sheet5").Cells(i, 8).Value

            Else
            End If
    Next i
Next j
 
End Sub
 
The following should do it

Code:
Dim i As Long
Dim j As Long

Sheet4LastRow = Worksheets("Sheet4").Range("D" & Rows.Count).End(xlUp).Row
sheet5LastRow = Worksheets("Sheet5").Range("A" & Rows.Count).End(xlUp).Row

    For j = 60 To Sheet4LastRow
        For i = 1 To sheet5LastRow
            If Worksheets("sheet4").Cells(j, 4).Value = Worksheets("sheet5").Cells(i, 1).Value _
                And Worksheets("Sheet5").Cells(j, 5).Value = Worksheets("Sheet5").Cells(i, 2).Value Then
                Worksheets("Sheet4").Cells(j, 1).Value = Worksheets("Sheet5").Cells(i, 3).Value
                Worksheets("Sheet4").Cells(j, 3).Value = Worksheets("Sheet5").Cells(i, 4).Value
                Worksheets("Sheet4").Cells(j, 6).Value = Worksheets("Sheet5").Cells(i, 5).Value
                Worksheets("Sheet4").Cells(j, 7).Value = Worksheets("Sheet5").Cells(i, 6).Value
                Worksheets("Sheet4").Cells(j, 8).Value = Worksheets("Sheet5").Cells(i, 8).Value

            Else
            End If
    Next i
Next j
 
End Sub

Without seeing your data the above may not be correct
Always try on a copy of your file just in case
 
Which is what you asked for!

Can you please provide a sample file together with clear instructions on what the data flow can be
 
@Hui
Have uploaded sample file and as shown in below images, data is written on header file if any new row is inserted.

Any suggestion to reference above code to always write data below header file row 17 even if users add row above.

Kindly have a look at my code in attached sample file.

Thanks for assisting...

Before

upload_2016-5-21_0-12-17.png

After row insert and new name added from planning sheet - row 18 has been overwritten the header file

upload_2016-5-21_0-13-50.png
 

Attachments

  • testfileAK-3.xlsm
    68.9 KB · Views: 0
Back
Top