Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Delete columns

Hi,
Could someone give me a code that will delete every other colum
between cells B:BA starting with cell B. There are 52 cells betweee
B:BA including them. Don't know if that helps or not. Here is a cod
I tried that basically took a long time before deleting all columns:

Dim i As Long

For i = 52 To 2 Step -1
Columns(i + 1).EntireColumn.Delete
Next i

Since this is a relatively short code, could someone break it down fo
me also? I am really trying to learn this stuff, I have bought 3 book
but I just never feel like reading them after work. Thanks,
Scott

--
Message posted from http://www.ExcelForum.com

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,337
Default Delete columns

I don't know if this is faster. Modify to columns,etc.
For row_index = lastrow To 1 Step -1
If row_index mod 2 =1 then
Rows(row_index).delete
End If
Next
or

Sub DeleteAltCols()
Dim i As Integer
For i = Columns.Count To 1 Step -1
If i Mod 2 = 0 Then Cells(1, i).EntireColumn.Delete
Next
End Sub
or to delete all after selecting.
For i = delRange.Column + 2 To _
Cells.SpecialCells(xlCellTypeLastCell).Column Step 2
Set delRange = Union(delRange, Cells(1, i))
Next i
delRange.EntireColumn.Delete

--
Don Guillett
SalesAid Software

"Scottmk " wrote in message
...
Hi,
Could someone give me a code that will delete every other column
between cells B:BA starting with cell B. There are 52 cells betweeen
B:BA including them. Don't know if that helps or not. Here is a code
I tried that basically took a long time before deleting all columns:

Dim i As Long

For i = 52 To 2 Step -1
Columns(i + 1).EntireColumn.Delete
Next i

Since this is a relatively short code, could someone break it down for
me also? I am really trying to learn this stuff, I have bought 3 books
but I just never feel like reading them after work. Thanks,
Scott.


---
Message posted from
http://www.ExcelForum.com/



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Delete columns

Don,
none of those seemed to work for me. It's possible I'm not allowing i
enough time. I have anywhere from 50-150 rows of actual data, and the
all rows underneath (yes, all the way down to row 65536) contains "-".
How long should the module take to run? Based on what I've told you
which would be the fastest?

Thanks, I appreciate any assistanc

--
Message posted from http://www.ExcelForum.com

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Delete columns

OK, I got one of them to work:

Sub DeleteAltCols()
Dim i As Integer
For i = Columns.Count To 1 Step -1
If i Mod 2 = 0 Then Cells(1, i).EntireColumn.Delete
Next
End Sub

But man, it took like 5 minutes to run. The part where I could tell i
was actually deleting didn't seem to take long at all, but the par
before that took a long time. Any suggestions

--
Message posted from http://www.ExcelForum.com



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Delete columns

Don,
no, it wasn't a different question. Since you gave me so man
different options on how to handle the situation, I was just giving yo
more information on the sheet I was trying to use it for. ...so that yo
could hopefully recommend the most appropriate code (fastest) to get th
job done.

Thank

--
Message posted from http://www.ExcelForum.com

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Delete columns

Don,
Actually, I think I have solved all of my problems...thanks to you.
However, you have me puzzled with your last post. I'm not sure wha
you mean by turn off screen updating and calculating during macro...ho
do I do that?

Thanks again for all of your help,
Scot

--
Message posted from http://www.ExcelForum.com

  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,337
Default Delete columns


application.screenupdating=false
Application.Calculation = xlCalculateManual
code
application.screenupdating=true
Application.Calculation = xlCalculateautomatic
--
Don Guillett
SalesAid Software

"Scottmk " wrote in message
...
Don,
Actually, I think I have solved all of my problems...thanks to you.
However, you have me puzzled with your last post. I'm not sure what
you mean by turn off screen updating and calculating during macro...how
do I do that?

Thanks again for all of your help,
Scott


---
Message posted from
http://www.ExcelForum.com/



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
delete columns if 0 jatman New Users to Excel 2 January 3rd 09 04:39 AM
Delete Columns Bernie New Users to Excel 1 February 28th 07 10:15 PM
merge text from 2 columns into 1 then delete the old 2 columns sleepindogg Excel Worksheet Functions 4 March 30th 06 07:25 PM
Can't delete columns Buss Excel Discussion (Misc queries) 3 December 16th 05 07:28 PM
Delete columns Elsie Excel Programming 1 February 28th 04 03:08 AM


All times are GMT +1. The time now is 06:05 AM.

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"