I'm looking to concatenate the values in the same row for two separate columns, e.g., A1 and B1, into column C1, and to complete this task whenever values change in an identified range, e.g., A1:B10. I will in turn use the concatenated values in column C in my code, e.g., using vlookup. I understand that I can do this without VBA, however I need help coding in VBA please.
One or both of the values in cells A1 and B1 could be blank at any given time and I seem to be getting errors. Here's what I have so far. Any help is appreciated. Thanks! I'm sure I'm missing a lot and am happy to answer any questions.
One or both of the values in cells A1 and B1 could be blank at any given time and I seem to be getting errors. Here's what I have so far. Any help is appreciated. Thanks! I'm sure I'm missing a lot and am happy to answer any questions.
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim c, changedRange as Range
Dim testVal1, testVal2, Concat as String
Const myRange = "A1:B10"
Const concatRange= "C1:C10"
Set changedRange = Intersect (Target, Range(myRange))
If Not changedRange Is Nothing Then
For each c in changedRange
testVal1 = c.Value
testVal2 = c.Value
Concat = testVal1 & testVal2
Range(concatRange).Value = Concat
Next c
End if
End sub