Merged Cells and wrap text with Macro

scriptebay

New Member
Joined
Feb 24, 2011
Messages
1
There are 2 parts of the csv file which I am working on. Part 1 to delete particular columns is completed. What I need help is

# How to wrap & merge information from different column/rows
# run as single script

Part 1 completed

Code:
Sub Deletecolumns()
'Find last column with data in Row 1
v = Array("Item Number", "Item Title")
lastCol = Cells(1, Columns.Count).End(xlToLeft).Column
'Loop through columns, starting at the last one
For delCol = lastCol To 1 Step -1
'Delete columns with specific Name in Row 1
bFound = False
For i = LBound(v) To UBound(v)
  If InStr(1, Cells(1, delCol), v(i), vbTextCompare) And _
   Len(Cells(1, delCol)) = Len(v(i)) Then
    bFound = True
    Exit For
  End If
Next i
If bFound Then _
  Cells(1, delCol).EntireColumn.Delete
Next delCol
End Sub

Part 2 where I need help is that the name and address are in different columns

Buyer Fullname|Buyer Address 1|Buyer Address 2|Buyer City|Buyer State|Buyer Zip|Buyer Country

current information looks like

XYZ WXY 162 robert dr ladson sc 29456 United States

The way I want is that the macro should compile the information either as

Buyer Fullname
Buyer Address 1
Buyer Address 2
Buyer City Buyer State Buyer Zip
Buyer Country

example

XYZ WXY
162 robert dr
ladson sc 29456
United States

Note: one check has to be that if "Buyer Address 2" is empty then it should ignore.

Part 3 - I would need to make this as single script which will delete the columns and merge address

Appreciate if anyone can help.
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off

Forum statistics

Threads
1,224,607
Messages
6,179,871
Members
452,948
Latest member
UsmanAli786

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top