PDA

View Full Version : Save Conct to Variable



Djblois
08-17-2007, 06:51 AM
I am trying to get create code that will loop through the selected range and concatnate it into a variable to be posted after it is completed. This is what I tried:

Sub TestCode()

Dim rngCode As Range
Dim stgCodes As String

i = 0
For Each rngCode In Selection.Areas
With Application.WorksheetFunction
stgCodes = "=CONCATENATE('rngcode',""?|"")"
End With
Next
End Sub

p45cal
08-17-2007, 07:02 AM
Sub blah()
For Each cll In Selection.Cells
myvariable = myvariable & cll.Value
Next cll
MsgBox myvariable
End Sub?
p45cal

Djblois
08-17-2007, 07:12 AM
Thank you,

I am closer now. Here is what I have:

Sub TestCode()

Dim rngCombine As Range, rngCode As Range
Dim stgCodes As String

i = 0
For Each rngCode In Selection.Areas
If stgCodes = "" Then
stgCodes = rngCode.Value & "?|"
Else
stgCodes = stgCodes & rngCode.Value & "?|"
End If
Next
End Sub

But it is giving me a type mismatch on rngCode.Value

rory
08-17-2007, 07:34 AM
Try this:
Sub TestCode()

Dim rngCombine As Range, rngArea As Range, rngCode As Range
Dim stgCodes As String

i = 0
For Each rngArea In Selection.Areas
For Each rngCode In rngArea.Cells
If stgCodes = "" Then
stgCodes = rngCode.Value & "?|"
Else
stgCodes = stgCodes & rngCode.Value & "?|"
End If
Next rngCode
Next rngArea
End Sub

rory
08-17-2007, 07:35 AM
PS and you need to do something with stgCodes at the end!