ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Adding a counter to ranges (https://www.excelbanter.com/excel-programming/365839-adding-counter-ranges.html)

wmureports

Adding a counter to ranges
 
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


Norman Jones

Adding a counter to ranges
 
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
'<<=============



--
---
Regards,
Norman



"wmureports" wrote in message
oups.com...
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




wmureports

Adding a counter to ranges
 
worked like a charm thanks.


Norman Jones wrote:
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
'<<=============



--
---
Regards,
Norman



"wmureports" wrote in message
oups.com...
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




All times are GMT +1. The time now is 05:36 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com