Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 397
Default Delete every 2nd column from fixed starting point

Howdie,
Can anyone help with VB to do the following: I would like to delete
columns F and G, then skip H and I, delete j and k, skip l and m, delete
n and o etc

So basically starting at F delete two columns, skip two columns, delete
two columns etc until no more data in the columns...

Thanks guys, appreciate your help

Regards

D



*** Sent via Developersdex http://www.developersdex.com ***
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Delete every 2nd column from fixed starting point

For i = 26 To 6 Step -4
Columns(i).Resize(, 2).Delete
Next i

--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"Darin Kramer" wrote in message
...
Howdie,
Can anyone help with VB to do the following: I would like to delete
columns F and G, then skip H and I, delete j and k, skip l and m, delete
n and o etc

So basically starting at F delete two columns, skip two columns, delete
two columns etc until no more data in the columns...

Thanks guys, appreciate your help

Regards

D



*** Sent via Developersdex http://www.developersdex.com ***



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 94
Default Delete every 2nd column from fixed starting point

Interesting mathematics question. : You should delete from the right to left
instead of from left to right. (in fact, always do this.)

Try the macro below. It should work no matter how many columns you've got in
the worksheet. Also, it assumes data starts in column A.

Sub go_delete()
Dim tmp as Integer
Dim tmp2 as Integer
Dim tmp_address As String, row_count As Single

With ActiveSheet.UsedRange
tmp = Fix((.Columns.Count - 5) / 4)
If (.Columns.Count - 5) Mod 4 0 Then
tmp = tmp + 1
End If
tmp_address = .Address(False, False)
row_count = .Rows.Count
End With
With ActiveSheet.Range(tmp_address)
With .Offset(0, 5).Resize(row_count, .Columns.Count - 5)
For tmp2 = tmp To 1 Step -1
With .Columns(4 * tmp2 - 3)
.Resize(row_count, 2).EntireColumn.Delete
End With
Next
End With
End With
End Sub

Regards,
Edwin Tam

http://www.vonixx.com



"Darin Kramer" wrote:

Howdie,
Can anyone help with VB to do the following: I would like to delete
columns F and G, then skip H and I, delete j and k, skip l and m, delete
n and o etc

So basically starting at F delete two columns, skip two columns, delete
two columns etc until no more data in the columns...

Thanks guys, appreciate your help

Regards

D



*** Sent via Developersdex http://www.developersdex.com ***

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 397
Default Delete every 2nd column from fixed starting point


Thanks Edwin,

It works perfectly!!!

REgards

Darin


*** Sent via Developersdex http://www.developersdex.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
Automatic recognition of a starting point for a column calculation GK[_2_] Excel Worksheet Functions 2 March 30th 10 10:33 PM
Select all rows on a sheet from a fixed starting point Niniel Excel Discussion (Misc queries) 5 February 8th 08 08:50 PM
bar chart starting point lnoles Charts and Charting in Excel 1 October 14th 05 02:16 PM
How do I delete data in a column from a certain point on? carolineeg Excel Worksheet Functions 0 May 19th 05 03:20 PM
averaging from a fixed point to a non-fixed point? Nascent Excel Programming 2 May 24th 04 05:41 AM


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

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"