A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Excel » Worksheet Functions
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

delete alternate columns...



 
 
Thread Tools Display Modes
  #1  
Old November 16th, 2003, 01:43 PM
external usenet poster
 
Posts: n/a
Default delete alternate columns...

Need a macro/function that'll delete every other column.
THX
Scottie
  #2  
Old November 16th, 2003, 03:02 PM
Vasant Nanavati
external usenet poster
 
Posts: n/a
Default delete alternate columns...

Something like:

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

--

Vasant



wrote in message
...
Need a macro/function that'll delete every other column.
THX
Scottie



  #3  
Old November 16th, 2003, 03:03 PM
Bob Phillips
external usenet poster
 
Posts: n/a
Default delete alternate columns...

answered in .misc.

If posting to multiple groups, best to do it in a single post, not multiple
postings.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

wrote in message
...
Need a macro/function that'll delete every other column.
THX
Scottie



  #4  
Old November 16th, 2003, 03:06 PM
Ken Wright
external usenet poster
 
Posts: n/a
Default delete alternate columns...

This will delete Col B, D, F etc onwards to the end of your data. If you want
A, C, E etc to go, then change the 2 to a 1 in teh line For x = 2 To lc (to
For x = 1 To lc)

Sub DelCols()

Dim LastCol As Integer
Dim lc As Integer
Dim x As Integer

Application.ScreenUpdating = False

LastCol = ActiveSheet.UsedRange.Column - 1 + _
ActiveSheet.UsedRange.Columns.Count

lc = Int(LastCol / 2)

For x = 2 To lc
ActiveSheet.Columns(x).Delete
Next x

Application.ScreenUpdating = True

End Sub

--
Regards
Ken....................... Microsoft MVP - Excel
Sys Spec - Win XP Pro / XL 00/02/03

----------------------------------------------------------------------------
Newsgroups - Where you really can get a free lunch!!
----------------------------------------------------------------------------



wrote in message
...
Need a macro/function that'll delete every other column.
THX
Scottie



---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.541 / Virus Database: 335 - Release Date: 14/11/2003


  #5  
Old November 16th, 2003, 03:09 PM
J.E. McGimpsey
external usenet poster
 
Posts: n/a
Default delete alternate columns...

one way:

Public Sub DelEveryOtherColumn()
Dim result As Integer
Dim cell As Range
Dim delRange As Range
Dim i As Integer
Dim refStr1 As String
Dim refStr2 As String
If Application.ReferenceStyle = xlR1C1 Then
refStr1 = "1"
refStr2 = "2"
Else
refStr1 = "A"
refStr2 = "B"
End If
result = MsgBox(prompt:="Start with Column " & _
refStr1 & "?" & vbNewLine & vbNewLine & _
"Click ""Yes"" for " & refStr1 & ", ""No"" for " & _
refStr2, Title:="Delete Alternate Columns", _
Buttons:=vbYesNoCancel)
If result = vbCancel Then Exit Sub
Set delRange = Cells(1, 2 + (result = vbYes))
For i = delRange.Column + 2 To _
Cells.SpecialCells(xlCellTypeLastCell).Column Step 2
Set delRange = Union(delRange, Cells(1, i))
Next i
delRange.EntireColumn.Delete
ActiveSheet.UsedRange
End Sub


In article ,
wrote:

Need a macro/function that'll delete every other column.
THX
Scottie

  #6  
Old November 17th, 2003, 03:39 AM
Scottie
external usenet poster
 
Posts: n/a
Default delete alternate columns...

Sorry...
-----Original Message-----
answered in .misc.

If posting to multiple groups, best to do it in a single

post, not multiple
postings.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

wrote in message
...
Need a macro/function that'll delete every other column.
THX
Scottie



.

 




Thread Tools
Display Modes

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

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 07:20 AM.


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