decadence
Well-known Member
- Joined
- Oct 9, 2015
- Messages
- 525
- Office Version
- 365
- 2016
- 2013
- 2010
- 2007
- Platform
- Windows
Hi, How can I delete only empty columns within a selected range
This is the code I am using, It merges columns together based on string delimited input but I want to delete only the empty columns from the column selection, Can someone help with this please
This is the code I am using, It merges columns together based on string delimited input but I want to delete only the empty columns from the column selection, Can someone help with this please
Code:
Sub MergeColumns()
Dim i As Long, addStr As String, a, b
If Selection.Columns.count = 1 Then Exit Sub
If Not Selection.Cells.CountLarge / Selection.Columns.count = 1048576 Then Exit Sub
[COLOR="#008000"]'Call Optimize_Begin[/COLOR]
On Error Resume Next
addStr = InputBox("Deliminate Columns By...", "Enter Deliminator...")
If StrPtr(addStr) = 0 Then
[COLOR="#008000"]'Call Optimize_End[/COLOR]
Exit Sub
End if
With Intersect(ActiveSheet.UsedRange, Selection)
a = .Value
ReDim b(1 To UBound(a, 1), 1 To UBound(a, 2))
For i = 1 To UBound(a, 1)
If addStr = addStr Then b(i, 1) = Join(Application.Index(a, i, 0), addStr)
Next i
.Value = b
End With
[COLOR="#0000FF"] Selection.Columns(1).Offset(0, 1).Delete[/COLOR] [COLOR="#008000"]<----- This needs changing[/COLOR]
[COLOR="#008000"]'Call Optimize_End[/COLOR]
End Sub
Last edited: