PDA

View Full Version : Merge contents of rows if criteria is met



kn147
08-26-2015, 06:50 AM
I currently have some code that takes a users defined range from an input box which is in column B and then within that range merges columns D through F into column C and adds commas between the merged contents. But now I found out I have special cases which do not work with the code I have. What I'm trying to do is check if in column C, within the range I chose in column B, contains either one of the 8 or so words I came across so far, to then merge the contents of columns G and H into C and then add commas.

Here is the code I have that works for the original case. I really don't want to add to this code but rather just have a new sub and make a call when I need it.



Code:
Dim rng As Range
Dim Rng1 As Range
Dim InputRng As Range


xTitleIdRngMerge = "Range ***MUST START/END WITH COLUMN B***"


Set InputRng = Application.Selection
Set InputRng = Application.InputBox("Range : ***MUST START/END WITH COLUMN B*** Input form should be similar to $B$32:$B$10000", xTitleIdRngMerge, InputRng.Address, Type:=8)

For Each rng In InputRng.Cells
If rng.Value <> "" Then
For Each Rng1 In Range("D" & rng.Row & ":F" & rng.Row).Cells
If Rng1.Value <> "" Then
rng.Offset(0, 1).Value = rng.Offset(0, 1).Value & ", " & Rng1.Value
End If
Next
Range("D" & rng.Row & ":F" & rng.Row).ClearContents
End If
Next

I don't mind have each word I need to check for in a different block. I just don't know how to search for a word I need in column C and then if so merge data in G and H into C with commas

Hope I made sense