Quick question, changing cell values with help of integer variable

jonastjader

New Member
Joined
Dec 9, 2013
Messages
12
Hi,
I would like to change the value of the cells A1:24 to the value of integer i, so that A1=1, A2=2 and so on until A24=24.
I want to do this with the help of an integer i and a for loop. This is how far I have got, how do I proceed now?

Sub ForLoop()
Dim i As Integer
For i = 1 To 24
Range("solar!Ai")=i
End Sub
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Code:
Sub ForLoop()
  Dim i As Integer
  For i = 1 To 24
    Worksheets("Solar").Range("A" & i).Value2 = i
  Next i
End Sub


Sub ForLoop2()
  With Worksheets("Solar").Range("A1:A24")
    .Formula = "=Row()"
    .Value2 = .Value2
  End With
End Sub
 
Upvote 0
Code:
Sub ForLoop()
  Dim i As Integer
  For i = 1 To 24
    Worksheets("Solar").Range("A" & i).Value2 = i
  Next i
End Sub


Sub ForLoop2()
  With Worksheets("Solar").Range("A1:A24")
    .Formula = "=Row()"
    .Value2 = .Value2
  End With
End Sub

Or even....

Code:
Sub ForLoop3()
  Range("A1:A24") = Evaluate("ROW(1:24)")
End Sub
 
Upvote 0

Forum statistics

Threads
1,203,670
Messages
6,056,666
Members
444,881
Latest member
Stu2407

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