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
 

Some videos you may like

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.

VoG

Legend
Joined
Jun 19, 2002
Messages
63,650
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
 

drhatmrexcel

Board Regular
Joined
Oct 30, 2009
Messages
69
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".
 

Watch MrExcel Video

Forum statistics

Threads
1,122,514
Messages
5,596,611
Members
414,080
Latest member
penguin23

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
Top