Deleting Columns to the right - 1

  • Thread starter Thread starter AHizon
  • Start date Start date
A

AHizon

Hi,

I recorded a Macros in Excel but the Macros hard codes the columns of what to
delete. I want the Macros to delete only the columns to the right after it
finds the next cell that has text. I don't know what program to enter so
that it only deletes columns in between that have no text. Below is the
program auto-generated after I recorded a Macros:
Range("B1").Select
Range(Selection, Selection.End(xlToRight)).Select
Range("B1:G1").Select
Selection.EntireColumn.Delete

Can anyone help me?
 
This will delete all empty columns. That what you are after?
Sub delColumns()
Dim lastCol As Integer
lastCol = ActiveSheet.UsedRange.Column - 1 + _
ActiveSheet.UsedRange.Columns.Count
Application.ScreenUpdating = False
For c = lastCol To 1 Step -1
If IsEmpty(Cells(1, c)) And Cells(1, c). _
End(xlDown).Row = 65536 Then _
Cells(1, c).EntireColumn.Delete
Next c
Application.ScreenUpdating = True
End Sub
 
Yes...That is exactly what I wanted. Thanks so much!!!
This will delete all empty columns. That what you are after?
Sub delColumns()
Dim lastCol As Integer
lastCol = ActiveSheet.UsedRange.Column - 1 + _
ActiveSheet.UsedRange.Columns.Count
Application.ScreenUpdating = False
For c = lastCol To 1 Step -1
If IsEmpty(Cells(1, c)) And Cells(1, c). _
End(xlDown).Row = 65536 Then _
Cells(1, c).EntireColumn.Delete
Next c
Application.ScreenUpdating = True
End Sub
[quoted text clipped - 9 lines]
Can anyone help me?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top