View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 27,285
Default NEED HELP with Range command

Thanks for the kind words - hopefully I can live up to them.

Perhaps a different approach:
are you looping and using some criteria to see if the column should be
deleted? for demonstration, I will check if the cell in row 1 has a value
greater than 3:

Dim rng as Range, i as Long
for i = 100 to 1 step -1
if cells(1,i) 3 then
if rng is nothing then
set rng = cells(1,i)
else
set rng = union(cells(1,i),rng)
end if
end if
Next
if not rng is nothing then
'rng.EntireColumn.Delete
rng.EntireColumn.Select
end if


--
Regards,
Tom Ogilvy

"Dan Thompson" wrote in message
...
Yes thank you bro, I apreciate the concept of using the A:F,H:J ect.....
however the rest of the code is based on dynamic information so I have
know
way of knowing if it is going to be A:H or C:H or A:D you get the Idea.
The only way I can posibly think of that would work is to write some kind
of
code that would be smart enought to look at a line like this

MyString =
"A:A,B:B,C:C,D:D,E:E,F:F,G:G,H:H,K:K,N:N,Q:Q,R:R,S :S,T:T,X:X,AA:AA"
ect....

and be able to have some code convert the above line into somthing like
the
following

MyString = "A:H,K:K,N:N,Q:T,X:X,AA:AA"

But I didn't realy want to have to write code to do that because it seams
like alot of extra work when VBA should just be able to handle really long
strings like the first one assigned to a Range

example: MyRange = Range(MyString).Select

keep in mind this will work with the example I had above because it is
short
enough, I just didn't want to type in the actual string from my code
because
it is like 220 characters long or more.


"broro183" wrote:


Hi Dan,
Tom's given you the best answer already (split into 2 lots & start from
the right) but just to expand on it...

Your initial post stated:
Range("A:A,B:B,C:C,F:F,AB:AB,AC:AC,BF:BF").Select

This can be shortened to include any consecutive columns in the same
range ie
Range("A:C,F:F,AB:AC,BF:BF").Select
(This would happen if you left click on the first column eg A & then
held it down while dragging the mouse over the columns next to it eg B
& C.)

If you are just deleting them (I think?) it can be safely changed to
Range("A:C,F:F,AB:AC,BF:BF").delete

hth
Rob Brockett
NZ
always learning & the best way to learn is to experience...


--
broro183
------------------------------------------------------------------------
broro183's Profile:
http://www.excelforum.com/member.php...o&userid=30068
View this thread:
http://www.excelforum.com/showthread...hreadid=560324