View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 27,285
Default Need help: delete colums

Dim b as Long, c as Long
Dim i as Long
b = clng(Userform2.BeginWeek.Text)
c = clng(Userform2.EndWeek.Text)

i = 0
do
cells(10,2 + i).Value = b
b = b + 1
if b 52 then b = 1
i = i + 1
loop until b = c
set rng = Range(cells(10,2+i),cells(10,256))
rng.Entirecolumn.Delete

Test this on a copy of your worksheet.

--
Regards,
Tom Ogilvy

"Hans_" wrote in
message ...

Hi all,

I have a problem and don't know how to fix it.
I will explain what i want to do with the macro.

I have a form where users can fill in a beginweek and an endweek.
Now i want excel to place the beginweek in cell B10 and the next week
in cell C10 and so on. After excel did that i want excel to delete all
the columns behind the endweek.

Example: beginweek is week 10 and endweek is week 21. So cell B10
should be 10, cell C10 should be 11, cell C12 should be 12 and so on
till cell M10 is 21.
Excel then should delete every column behind column M, so from column
N.

Is this possible with a macro??

Then, is it also possible when i have a beginweek of week 48 and it
ends in week 5 of the next year...to have it automatically, after week
52 or 53, start with week 1? I hope this is possible.

Many thanks in advance!!!

Greets Hans


--
Hans_
------------------------------------------------------------------------
Hans_'s Profile:

http://www.excelforum.com/member.php...o&userid=25618
View this thread: http://www.excelforum.com/showthread...hreadid=390317