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
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
PS and you need to do something with stgCodes at the end!
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.