PC Review


Reply
Thread Tools Rate Thread

Deleting Columns to the right - 1

 
 
AHizon
Guest
Posts: n/a
 
      11th Oct 2007
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?

 
Reply With Quote
 
 
 
 
JW
Guest
Posts: n/a
 
      11th Oct 2007
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?


 
Reply With Quote
 
AHizon
Guest
Posts: n/a
 
      11th Oct 2007
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 With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Deleting columns Barry Lennox Microsoft Excel Misc 3 8th Jan 2009 10:00 PM
Adding Columns, Then deleting old columns May Microsoft Excel Misc 4 30th Oct 2008 04:44 PM
Combining Text from 2 Columns into 1 then Deleting the 2 Columns =?Utf-8?B?c2xlZXBpbmRvZ2c=?= Microsoft Excel Worksheet Functions 5 19th Sep 2008 12:36 AM
Deleting columns surg4u1975 Microsoft Excel New Users 3 16th Dec 2005 07:09 PM
deleting columns =?Utf-8?B?Y19uZXc=?= Microsoft Excel Misc 4 26th Oct 2005 02:46 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:05 PM.