Delete Range of Columns

  • Thread starter Thread starter James
  • Start date Start date
J

James

can you please show me how to delete the entire column starting in column f
until an empty column is encountered. thanks.
 
Sub Macro()
Dim lngLastcol as Long
lngLastcol = ActiveSheet.Cells.Find(What:="*", _
SearchDirection:=xlPrevious, SearchOrder:=xlByColumns).Column
Range("F1", Cells(1, lngLastcol)).EntireColumn.Delete
End Sub

If this post helps click Yes
 
Try something like the following:

Dim R As Excel.Range
Set R = Range("F1")
Do Until Application.CountA(R.EntireColumn) = 0
Set R = R(1, 2)
Loop
' the empty column will be delete with the other cols.
' to leave the blank column in place, uncomment the
' next line:
'Set R = R(1, 0)

Range(Range("F1"), R).EntireColumn.Delete


This will delete columns from F to the next empty column. That empty
column will be delete with the others. To leave the empty column
intact, uncomment the Set R = R(1,0) line of code.

Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group, 1998 - 2009
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)
 

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