Declaring a Variable

lsteffen

Board Regular
Joined
May 11, 2006
Messages
111
Good afternoon,

How do I make B1 in the following code be a variable so that when it fills down, it will change to B2, B3, B4 etc?

Range("G1").Value = Application.Rept(" ", NumSpaces) & [B1].Value
Worksheets("Data").Range("G1:G" & LastRow).FillDown

Thank you,

Liz
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
try this
Code:
Range("G1").Formula = "=REPT("" ""," & NumSpaces & ")&RC[-5]"
Worksheets("Data").Range("G1:G" & LastRow).FillDown
 
Upvote 0
That worked nicely, I tried to use it again in this case too, but what am I missing?

Range("G1").Select
ActiveCell.Formula = "=LEFT(RC[-3]&REPT(' ',10),10)"
Worksheets("Data").Range("G1:G" & LastRow).FillDown
Columns("G:G").Select
 
Upvote 0
I figured it out, here is what I updated it to:

Range("G1").Formula = "=LEFT(RC[-3]& REPT("" "",10),10)"
Worksheets("Data").Range("G1:G" & LastRow).FillDown

Thank you much!
Liz
 
Upvote 0
Hi Liz,

Just as an option you could also put all that on one line...!

Code:
Worksheets("Data").Range("G1:G" & lastrow).Formula = _
"=LEFT(RC[-3]& REPT("" "",10),10)"
 
Upvote 0

Forum statistics

Threads
1,224,518
Messages
6,179,259
Members
452,901
Latest member
LisaGo

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