How to do End(xlUp).Row + 1 using a loop in VBA

nkw2306

New Member
Joined
Jan 20, 2015
Messages
32
Office Version
  1. 2019
Platform
  1. Windows
HI. So I am using a loop to move data from one sheet to another but there are 3 sheets in all. I need it to look up each sheet before it moves data over to only paste in a blank cell.

Currently my macro is as follows

Rc = 2
For p = 1 To 3
For i = 5 To 3000
With Sheets("Data")
If Sheets("Data").Range("A" & i).Value = "" Then GoTo next_i
If Sheets("Data").Range("M" & i).Value = Sheets("Lookup").Range("P" & p).Value Then
Worksheets(Sheets("Data").Range("M" & i).Value).Range("A" & Rc).Value = Sheets("Data").Range("A" & i).Value

However I want Rc to be the end of the row on the individual tabs as the information is always in different rows.

Please help!!!
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
How about
Code:
For p = 1 To 3
   For i = 5 To 3000
      With Sheets("Data")
         If .Range("A" & i).Value = "" Then GoTo next_i
         If .Range("M" & i).Value = Sheets("Lookup").Range("P" & p).Value Then
            Worksheets(.Range("M" & i).Value).Range("A" & Rows.Count).End(xlUp).Offset(1).Value = Sheets("Data").Range("A" & i).Value
 
Upvote 0
You Legend Fluff!!!!

Thanks so much!

How about
Code:
For p = 1 To 3
   For i = 5 To 3000
      With Sheets("Data")
         If .Range("A" & i).Value = "" Then GoTo next_i
         If .Range("M" & i).Value = Sheets("Lookup").Range("P" & p).Value Then
            Worksheets(.Range("M" & i).Value).Range("A" & Rows.Count).End(xlUp).Offset(1).Value = Sheets("Data").Range("A" & i).Value
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,214,805
Messages
6,121,656
Members
449,045
Latest member
Marcus05

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top