Autofill Not Autofilling

jski21

Board Regular
Joined
Jan 2, 2019
Messages
155
Office Version
  1. 2016
Platform
  1. Windows
Good day all,

Trying to run a macro from a command button on one tab (Tab 1) to transform data on another tab (Tab 3). Conducting a VLOOKUP from Tab 3 into Tab 1 and then autofilling the data down with this code:

Sheets("Tab 3").Range("D2").Select
ActiveCell.FormulaR1C1 = "=VLOOKUP([@User],Tab 1!C[4]:C[6],3,FALSE)"
Range("D2").AutoFill Range("D2:D" & Range("C" & Rows.Count).End(xlUp).Row)

Seems right but after executing the 3rd line to autofill the VLOOKUP, nothing happens. Column C is completely full. What gives?


Thanks!

jski
 
Yes, but using Tab 3 as generic illustration. Should have changed that before I sent image.
 
Upvote 0

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Should have changed that before I sent image
No you shouldn't.

What happens with the below

VBA Code:
    With Sheets("Clockify")
        .Range("D2:D" & .Range("C" & Rows.Count).End(xlUp).Row).FormulaR1C1 = "=VLOOKUP([@User],'Tab 1'!C[4]:C[6],3,FALSE)"
    End With

Assuming that Tab 1 is actually called Tab 1 although I doubt it
 
Upvote 0
Solution
Actually, it is. Thanks Mark. That did it. With Sheets / End With?

What are the major differences one should keep in mind in running code from your PERSONAL file as opposed to actually containing it in within the workbook the macro will be used?
 
Upvote 0
With Sheets / End With?
Just saves writing something multiple times (see the below as to what it looks like without it), it also means Excel only evaluates it once (only matters when using a lot of references to whatever you have on the With line).

VBA Code:
Sheets("Clockify").Range("D2:D" & Sheets("Clockify").Range("C" & Rows.Count).End(xlUp).Row).FormulaR1C1 = "=VLOOKUP([@User],'Tab 1'!C[4]:C[6],3,FALSE)"

What are the major differences one should keep in mind in running code from your PERSONAL file as opposed to actually containing it in within the workbook the macro will be used?
Biggest one is remembering the workbook the code is working on is the Active workbook and not ThisWorkbook
 
Upvote 0
Instructive and very helpful. Thanks Mark and to all who contributed to this thread.
 
Upvote 0
You're welcome, happy we could help
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,887
Messages
6,175,199
Members
452,617
Latest member
Narendra Babu D

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