Vlookup into next blank column

Janspook03

New Member
Joined
May 13, 2024
Messages
2
Office Version
  1. 365
Platform
  1. Windows
Hi everyone,
I'm an excel newbie and trying to figure out how to make something work in VBA. Y'all seem like a really nice bunch, so I'm hoping you can help me out!

I've managed to automatically create a pivot table containing days worked per week per person from a raw data file and would like to create a macro that will automatically show the values of that pivot table into an overview. So I can collect the data for every month in one sheet.
To achieve this, I figured I could use a VLookUp code that transfers the data from my pivot table to the overview adding 4 to 5 weeks every month.

I got this far from another guide I found online:
VBA Code:
Sub VLOOKUPAnotherSheet()
    
    For Each cell In ThisWorkbook.Sheets("Pastetest").Range("A2:A2000")
    cell.Offset(0, 1) = Application.VLookup(cell, Sheets("Pivot Sheet").Range("A3:B2000"), 2, False)
    Next

End Sub

But I can't figure out how to change the code to add the vlookup to the next blank column.
(every time I try to add an .End(x1Up) or other things I've seen in other posts, it just doesn't work.)

If anyone can help me to make sense of it all, it would be greatly appreciated!
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
The End(x1Up) you have seen in other posts should be End(xlUp) i e. a lower case L and that would be looking for the last row with data not a column
 
Upvote 0
The End(x1Up) you have seen in other posts should be End(xlUp) i e. a lower case L and that would be looking for the last row with data not a column
Haha that certainly clears things up! Thanks for that.

Though if I try the following I get a runtime error. So I'm still not sure how to make it scoot over. Any ideas?

Excel Formula:
Sub VLOOKUPAnotherSheet()
    
    For Each cell In ThisWorkbook.Sheets("Pastetest").Range("A2:A" & Sheets("Pastetest").Range("A" & Column.Count).End(xlToLeft).Row)
    cell.Offset(0, 1) = Application.VLookup(cell, Sheets("Pivot Sheet").Range("A3:B2000"), 2, False)
    Next

End Sub
 
Upvote 0
Rich (BB code):
ThisWorkbook.Sheets("Pastetest").Range("A2:A" & Sheets("Pastetest").Range("A" & Column.Count).End(xlToLeft).Row)
Can you explain in words what you are trying to do with the line above as the bit in red doesn't make sense with the rest of the line
 
Upvote 0
In this case, you're trying to find the last row in Column A, which should look like this:

VBA Code:
Sub VLOOKUPAnotherSheet()
    Dim cell As Range
    
    For Each cell In ThisWorkbook.Sheets("Pastetest").Range("A2:A" & Sheets("Pastetest").Range("A" & Rows.Count).End(xlUp).row)
        cell.Offset(0, 1) = Application.VLookup(cell, Sheets("Pivot Sheet").Range("A3:B2000"), 2, False)
    Next

End Sub
 
Upvote 0

Forum statistics

Threads
1,224,818
Messages
6,181,152
Members
453,021
Latest member
Justyna P

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