Autofill

P

paulinoluciano

"Is there some VBA code with which could I autofill the column B with
some formula exactly with the same size in A while this could be
variable among the sheets?"
I have used the code:

Sub Macro1()
Range("B1").Select
ActiveCell.FormulaR1C1 = "Random 1"
Selection.AutoFill Destination:=Range("B1:B20")
End Sub

But in this case I have the fills with the words Random 1, Random 2,
Random 3,... Random 20. The problem is that in other situations the
random numbers could be 1000 or more and I would not like to do that
manually.
 
B

Bob Phillips

Is this what you mean

Sub Macro1()
Range("B1:B20").Value = "Random 1"
End Sub


--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)
 
P

paulinoluciano

Hi,
No, it is not!
I would like to autofill the column B with Random 1, Random 2, Random
3, Random 5,.... Random n. However this autofill would need to be of
the same size of the column A. Example: If column A has cells
containing data until row 20 thus the macro should add the name random
until there on column B. If column B has cells containing data until
row 1323 thus it should has the name rando until B1323...
 
D

Dave Peterson

Maybe...

Sub Macro1()

Dim LastRow as long
dim wks as worksheet

for each wks in activeworkbook.worksheets
with wks
lastrow = .cells(.rows.count,"A").end(xlup).row
.range("b1:b" & lastrow).formular1c1 = "Random 1"
'or ????
.range("B1:b" & lastrow).formula = "=Rand()"
end with
next wks
End Sub
 
P

paulinoluciano

Yes, it is almost the first trend... However instead exhibit always
"Random 1" I have to exhibit Random 1, Random 2, Random 3....
 
D

Dave Peterson

based on what?

Option Explicit
Sub Macro1()
Dim LastRow As Long
Dim wks As Worksheet

For Each wks In ActiveWorkbook.Worksheets
With wks
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
With .Range("B1:B" & LastRow)
.Formula = "=""Random "" & Row()"
.Value = .Value
End With
End With
Next wks
End Sub
 
P

paulinoluciano

Based on starting as Random 1 and finishing progressively until the
last cell containing data in A column.
 
Top