VBA Question from a newby

craig8125

New Member
Joined
Nov 19, 2009
Messages
26
I am working through the VBA for Dummies book on excel 2007.

And have entered the code:

Sub FillRange()
Dim Count As Long
For Count = 1 To 100
ActiveCell.Offset(Count - 1, 0) = Rnd
Next Count
End Sub

Don't laugh please we all have to start somehwere, the thing is the code is supposed to fill cells A1:A100 with 1 to 100 (I add the Step 1 variable to it also)

All I get is seemingly randon decimals ie 0.95 in all of the cells

Can anyone shed some light on what I am doing wrong please

Thanks
Craig
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Should it be

Rich (BB code):
Sub FillRange()
    Dim Count As Long
    For Count = 1 To 100
             ActiveCell.Offset(Count - 1, 0) = Count
    Next Count
End Sub
 
Upvote 0
Change the RND to Count
ie
ActiveCell.Offset(Count - 1, 0) = Count
the RND enters random numbers whereas Count enters the value of Count which is incrementing from 1 to 100 based on the line above that reads "For Count = 1 To 100".
 
Upvote 0

Forum statistics

Threads
1,214,832
Messages
6,121,841
Members
449,051
Latest member
excelquestion515

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