Autofill Macro for Rows and Columns

jmac121233

New Member
Joined
Oct 18, 2010
Messages
5
I've searched existing threads but haven't had much luck finding the answer I need.

I have a formula in cell B2 that I'm trying to copy across all columns (with data in Row 1) and down all rows (with data in Column A). The number of rows and columns is going to be constantly changing (for example, this week I may need to copy B2 from B2:G50, but next week it may be B2:J100). I've figured out how to copy the formula down every row, but cannot figure out how to copy the formula across all columns. Any help would be greatly appreciated!! Macro code is provided below:

Also, much less importantly, is there a way to make my vlookup range dynamic as well?

Sheets("One").Select
Range("B2").Select
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = _
"=VLOOKUP(RC1,Data!R3C1:R33C17,HLOOKUP(R1C,Data!R1C1:R2C17,2,FALSE),FALSE)"
Range("B2").Select
Selection.AutoFill Destination:=Range("B2:B" & Range("A" & Rows.Count).End(xlUp).Row)
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
According to My understandings.

Copy the Formula and Press Ctrl+Shift+End then paste.

If my assumption is wrong, please provide a Sample file. :)
 
Last edited:
Upvote 0
Because I'm going to have dozens of worksheets that this copy/paste needs to be done on, I don't want this to be a manual process. I'm looking to have the macro do it for me.

Sorry, I don't see the option to attach the workbook.
 
Upvote 0
Has anybody had any luck setting a macro to autofill down all rows and then across all columns? I'm continuing to have no luck with my efforts to get this to work. Thanks
 
Upvote 0
Krishhi - Thanks for the offer to help! I FINALLY figured it out. The code I used is...

Sheets("One").Select
Dim LR As Long, LC As Integer
LR = Cells(Rows.Count, "A").End(xlUp).Row
LC = Cells(1, Columns.Count).End(xlToLeft).Column
Range(Cells(2, 2), Cells(LR, LC)).Formula = "=VLOOKUP(RC1,Data!R3C1:R33C17,HLOOKUP(R1C,Data!R1C1:R2C17,2,FALSE),FALSE)"
 
Upvote 0

Forum statistics

Threads
1,216,520
Messages
6,131,135
Members
449,626
Latest member
Stormythebandit

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