View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Mike Fogleman[_2_] Mike Fogleman[_2_] is offline
external usenet poster
 
Posts: 206
Default Selecting Columns

Sub test()
Dim i As Long
Dim numcolumn As Long
numcolumn = Range("J2")
'Column AC is 18 columns from K
For i = 18 To numcolumn Step -1
Columns("K:K").Offset(0, i).Delete
Next

End Sub

Mike F

"Simon Lloyd" wrote in message
...

This should do what you need
Dim i As Long
Dim numcolumn As Long
numcolumn = Range("J2")
For i = numcolumn To 1 Step -1
Columns("K:K").Offset(0, i).Delete
Next ;244984 Wrote:
Hi all!

I am trying to run a program which would allow me to do the following:

I have a number that is put in Cell J2 by me or any other user. That
number denotes the number of columns away from column K that I need to
start deleting from; I will delete from there all the way up to column
AC. So, fo rexample, I have the number 5 in cell J2. This would mean I
need to start deleting from column P all the way to column AC. If the
number is 3 in J2, then I would delete from column M to column AC. I
don't know the method to select the columns based on the number. So
far I have:

NumColumn = Range("J2")
Range("K2").Select
ActiveCell.Offset(0,NumColumn)

From this point on, I don't know how to select the column I'm in after
the offset all the way to column AC. If someone can help with this, I
would be forever grateful!

Thanks in advance!



--
Simon Lloyd

Regards,
Simon Lloyd
'The Code Cage' (
http://www.thecodecage.com)
------------------------------------------------------------------------
Simon Lloyd's Profile:
http://www.thecodecage.com/forumz/member.php?userid=1
View this thread: http://www.thecodecage.com/forumz/sh...ad.php?t=68330