ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Convert string to variable (https://www.excelbanter.com/excel-programming/373838-convert-string-variable.html)

Jason Morin

Convert string to variable
 
I have several variables named RandRow1, RandRow2, etc. that have been
populated with values. How do I convert a concatenated string into an actual
variable? In this case it's RandRow & i where i = 1 to 10. Thanks.

Dim RandRow1 as Long
Dim RandRow2 as Long
etc.

With Sheets("writtentest")
For i = 1 To 10
.Cells(i, "A") = Sheets("words").Cells(RandRow & i, "A")
Next
End With

Dave Peterson

Convert string to variable
 
maybe...

..Cells(i, "A") = Sheets("words").Cells(RandRow + i, "A")

& is usually used to concatenate strings: "Jason" & " " & "Morin"
+ is used to add numbers

(Excel sometimes allows + with strings, too. But it's better to be safe.)

Jason Morin wrote:

I have several variables named RandRow1, RandRow2, etc. that have been
populated with values. How do I convert a concatenated string into an actual
variable? In this case it's RandRow & i where i = 1 to 10. Thanks.

Dim RandRow1 as Long
Dim RandRow2 as Long
etc.

With Sheets("writtentest")
For i = 1 To 10
.Cells(i, "A") = Sheets("words").Cells(RandRow & i, "A")
Next
End With


--

Dave Peterson

moon[_7_]

Convert string to variable
 

Public Sub Test123()

Dim rng As String
Dim x, y As Integer

x = 1: y = 8

'Construction of string -- A1:E8
rng = "A" & LTrim(Str(x)) & ":E" & LTrim(Str(y))

ActiveSheet.Range(rng).Select

End Sub





"Jason Morin" schreef in bericht
...
I have several variables named RandRow1, RandRow2, etc. that have been
populated with values. How do I convert a concatenated string into an
actual
variable? In this case it's RandRow & i where i = 1 to 10. Thanks.

Dim RandRow1 as Long
Dim RandRow2 as Long
etc.

With Sheets("writtentest")
For i = 1 To 10
.Cells(i, "A") = Sheets("words").Cells(RandRow & i, "A")
Next
End With





All times are GMT +1. The time now is 03:12 PM.

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