Some basic VBA code

AndreaG

New Member
Joined
May 14, 2015
Messages
23
Apologies in advance - I have read the "VBA programming for dummies" book but I am still struggling with writing VBA code.

I'm sure what I want to do is very straight forward but I can't work it out - please help!

I need to enter number 100 into cell G100, number 101 into cell G200, number 102 into cell G300 etc etc upto number 600.

I'd like it in code as the spreadsheet is a moving document and the requirements might change - so I need to be able to populate it quickly.

Many thanks - hopefully the more I can work with real examples the more I'll understand.
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Welcome to the board.

Here is one way to do it:

Code:
Sub OneToSixHundred()

    Dim x As Long
    
    For x = 1 To 600
        Range("G" & x * 100) = x
    Next x
    
End Sub
 
Upvote 0
Welcome to the Board!

See if this gets you started:

<font face=Calibri><SPAN style="color:#00007F">Sub</SPAN> foo()<br>    <SPAN style="color:#00007F">Dim</SPAN> x <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN><br>    <SPAN style="color:#00007F">Dim</SPAN> i <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN><br>    <br>    i = 100<br>    <SPAN style="color:#00007F">For</SPAN> x = 100 <SPAN style="color:#00007F">To</SPAN> 600<br>        Range("G" & i).Value = x<br>        i = i + 100<br>    <SPAN style="color:#00007F">Next</SPAN> x<br>    <br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN></FONT>

HTH,
 
Upvote 0
Apologies in advance - I have read the "VBA programming for dummies" book but I am still struggling with writing VBA code.

I'm sure what I want to do is very straight forward but I can't work it out - please help!

I need to enter number 100 into cell G100, number 101 into cell G200, number 102 into cell G300 etc etc upto number 600.

I'd like it in code as the spreadsheet is a moving document and the requirements might change - so I need to be able to populate it quickly.

Many thanks - hopefully the more I can work with real examples the more I'll understand.

Andrea, I misread your post and started at 1 instead of 100. Smitty's solution should be what you're looking for.
 
Upvote 0

Forum statistics

Threads
1,214,950
Messages
6,122,436
Members
449,083
Latest member
Ava19

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