ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Delete columns (https://www.excelbanter.com/excel-programming/308786-delete-columns.html)

Scottmk[_32_]

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


Don Guillett[_4_]

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/




Scottmk[_33_]

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


Don Guillett[_4_]

Delete columns
 
Is this a different question?

--
Don Guillett
SalesAid Software

"Scottmk " wrote in message
...
Don,
none of those seemed to work for me. It's possible I'm not allowing it
enough time. I have anywhere from 50-150 rows of actual data, and then
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 assistance


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




Scottmk[_34_]

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


Scottmk[_35_]

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


Don Guillett[_4_]

Delete columns
 
You should always turn off screen updating and calculation during the macro.
Turn back on after.

--
Don Guillett
SalesAid Software

"Scottmk " wrote in message
...
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 it
was actually deleting didn't seem to take long at all, but the part
before that took a long time. Any suggestions?


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




Scottmk[_36_]

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


Don Guillett[_4_]

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/





All times are GMT +1. The time now is 12:24 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com