Home > Forum Home > Developing and Auditing Analytical Models > Concatenate two columns? > Problems with single words Share

Problems with single words

Excel Help for Problems With Single Words in Developing and Auditing Analytical Models


Forum TopicLogin

Problems With Single Words

Rate this:
(3/5 from 1 vote)
OopsI am using the following VBA code to concatenate two columns of data:
VBA Code:
Sub Combine_Columns()
Dim modifier As Variant
Dim word As Variant

Range("F4").Select 'Change as appropriate

For Each word In Range("D4", Range("D4").End(xlDown))
    For Each modifier In Range("B4", Range("B4").End(xlDown))
        ActiveCell.Formula = modifier & " " & word
        ActiveCell.Offset(1, 0).Select
Next
Next
Range("F4").Select

End Sub


This works great as long as there is more than 1 word in each column; However, when there is only one word in either column the macro will run indefinitely (combining words with blank cells). I've tried fixing this using a series of If statements, but I still can't get it to work (or at the very least prompt the user that more than 2 words must be used)   

Any help that you can offer would be much appreciated. 



 www.ProjectMatt.com
 Posted by on
 
View Full Post

Find relevant Excel templates and add-ins for Problems with single words in the