EZ: Autofill with a variable

yeoman12

New Member
Joined
Sep 28, 2010
Messages
4
This should be an easy one for someone...

I've managed to cobble together some code that does nearly everything I need, except for one lousy thing...
I need to add a new field in (S1) lets say FileNm and I need to populate that field from the first record to the last in my file.

I have looked at something like this...
Selection.AutoFill Destination:=Range("S2:S" & LastRow), Type:=xlFillDefault
or this
Range("S2").AutoFill Destination:=Range("S2:S" & LastRow, "File01")

Where LastRow is a variable I have defined earlier in the code as
LastRow = Range("J2").End(xlDown).Row

The problem is that instead of using a Type I'd really just like to call the value of another String variable I have defined earlier in my script, called File01 as I tried in the second example above.

This seems like something that should be pretty easy to do, I just cannot figure it out!
Thanks in advance.
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Hi

Try -

Code:
Range("S1:S" & LastRow).Filldown

Note the use of cell S1 which contains your file name.

hth

Mike
 
Upvote 0
I think this might be what you're after

Range("S2:S" & LastRow).value = "File01"
 
Upvote 0

Forum statistics

Threads
1,215,443
Messages
6,124,890
Members
449,194
Latest member
JayEggleton

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