ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Concatanate variable name (https://www.excelbanter.com/excel-programming/278409-concatanate-variable-name.html)

choco140

Concatanate variable name
 
I got four control on an userform named Date1, Date2, Date3 and Date4.
I am trying to fill them in with this small macro, it doesn't work
because my concatenation doesn't seem to be properly set up...

Sub Test
For i = 1 to 4
Date & i &.value = Range("A" & i).Value
Next i
End Sub

I got an error for "Date & i &.value", any idea how to solve this?

Thanks.

Jake Marx[_3_]

Concatanate variable name
 
Hi choco140,

You can't concatenate variable names directly, as VBA will not understand
it. You can, however, work with the Controls collection to do this:

Dim i As Integer

For i = 1 To 4
Me.Controls("Date" & CStr(i)).Text = _
Sheets("Sheet1").Cells(i, 1).Value
Next i

--
Regards,

Jake Marx
www.longhead.com


choco140 wrote:
I got four control on an userform named Date1, Date2, Date3 and Date4.
I am trying to fill them in with this small macro, it doesn't work
because my concatenation doesn't seem to be properly set up...

Sub Test
For i = 1 to 4
Date & i &.value = Range("A" & i).Value
Next i
End Sub

I got an error for "Date & i &.value", any idea how to solve this?

Thanks.



choco140

Concatanate variable name
 
Thanks.

"Jake Marx" wrote in message ...
Hi choco140,

You can't concatenate variable names directly, as VBA will not understand
it. You can, however, work with the Controls collection to do this:

Dim i As Integer

For i = 1 To 4
Me.Controls("Date" & CStr(i)).Text = _
Sheets("Sheet1").Cells(i, 1).Value
Next i




All times are GMT +1. The time now is 08:38 AM.

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