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. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
delete alternate columns...
Need a macro/function that'll delete every other column.
THX Scottie |
#2
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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 | |
|
|