Home > Forum Home > Developing and Auditing Analytical Models > Concatenate two columns? > Problem testing for range first Share

Problem testing for range first

Excel Help for Problem Testing For Range First in Developing and Auditing Analytical Models


Forum TopicLogin

Problem Testing For Range First

Rate this:
(3/5 from 1 vote)
OopsHi, I´m new to VBA and this forum and I´ve managed to get this macro to work for me. Until I added Russells extra bit of code to test for range first. I see it working away but it overwrites the results in cell F1.

The code I´m using is ...

VBA Code:
Sub combine_columns()
Dim columnC As Variant
Dim columnB As Variant
Dim columnA As Variant

Range("A1").Select
If ActiveCell.Offset(1, 0) <> "" Then
       Range(Selection, Selection.End(xlDown)).Select
End If
For Each columnA In Selection

Range("B1").Select
If ActiveCell.Offset(1, 0) <> "" Then
       Range(Selection, Selection.End(xlDown)).Select
End If
For Each columnB In Selection

Range("C1").Select
If ActiveCell.Offset(1, 0) <> "" Then
       Range(Selection, Selection.End(xlDown)).Select
End If
For Each columnC In Selection
                
Range("F1").Select 'Output column
        ActiveCell.Formula = columnA & " " & columnB & " " & columnC
        ActiveCell.Offset(1, 0).Select         
Range("F1").Select 'Output column

Next
Next
Next
End Sub

Any help would be gratefully received although it will have to be spelled out for me as I´m definitely not a natural VBAer.

p.s. A very minor point is that if one column is left blank the macro still works but leaves a double space between the two terms. Impossible for me to solve.
 Posted by on
 
View Full Post

Find relevant Excel templates and add-ins for Problem testing for range first in the