Cut and paste columns programmatically

D

David Portwood

Can I get some help coding something like the following:

If Range("E1").value = "YTD" then
'cut columns E, F, G
'paste columns E, F, G in front of column B
end if

Basically I want to swap three YTD columns to the front. I know how to grab
one column, Range("E1").EntireColumn, for instance, but how do I grab two
more adjacent columns? Or do I have two cut and paste three times?

I won't know in advance how many rows there might be.

Thanks in advance,
David Portwood
 
A

Alan

Using the macro recorder will show you what you want but it won't be as clean
as this:

If Range("E1").value = "YTD" then
Columns("E:G").Cut
Columns("B:B").Insert Shift:=xlToRight
End If


Alan
 
D

David Portwood

Perfect! I was hoping there would be something simple and direct just like
this. Thank you, Alan.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top