Adding a counter to ranges

W

wmureports

What i want to do is insert data into a range of rows. But instead of
staticly typing the rows I want them to be determined dynamically
through a counter variable. Heres and example of my code.

Dim counter As Integer

counter = 0

Do While counter < 20
counter = counter + 1

ThisWorkbook.Worksheets("Sheet1").Range("A1:A20") = counter
Loop


So instead of A1:A20 It will be A*counter value*:A*counter value*. My
problem is I dont know the proper syntax to add the actual counter
variable into to range
 
N

Norman Jones

Hi W,

Perhaps something like:

'=============>>
Public Sub Tester001()
Dim counter As Long

For counter = 1 To 20
ActiveSheet.Cells(counter, "A").Value = counter
Next counter
End Sub
'<<=============
 
W

wmureports

worked like a charm thanks.


Norman said:
Hi W,

Perhaps something like:

'=============>>
Public Sub Tester001()
Dim counter As Long

For counter = 1 To 20
ActiveSheet.Cells(counter, "A").Value = counter
Next counter
End Sub
'<<=============
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top