Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Deleting Columns to the right - 1

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?

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 638
Default Deleting Columns to the right - 1

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
AHizon wrote:
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?


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Deleting Columns to the right - 1

Yes...That is exactly what I wanted. Thanks so much!!!

JW wrote:
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
Hi,

[quoted text clipped - 9 lines]

Can anyone help me?


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Deleting columns Barry Lennox[_2_] Excel Discussion (Misc queries) 3 January 8th 09 10:00 PM
Adding Columns, Then deleting old columns May Excel Discussion (Misc queries) 4 October 30th 08 04:44 PM
Combining Text from 2 Columns into 1 then Deleting the 2 Columns sleepindogg Excel Worksheet Functions 5 September 19th 08 12:36 AM
deleting columns c_new Excel Discussion (Misc queries) 4 October 26th 05 02:46 PM
Deleting Columns Jim Berglund Excel Programming 2 July 20th 04 10:01 PM


All times are GMT +1. The time now is 04:26 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"