Live Chat & Podcast at 1:00PM Eastern on Sunday!
There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
Search
Business Applications
Tag Cloud
access acer asus bios bsod computer crash desktop dns driver drivers error ethernet excel freeze gaming graphics hard drive hardware hdmi internet laptop malware memory monitor motherboard network printer problem ram registry repair router slow software sound trojan ubuntu 11.10 uninstall usb video virus vista wifi windows windows 7 windows 7 32 bit windows 7 64 bit windows xp wireless
Search
Search for:
Tech Support Guy Forums > Software & Hardware > Business Applications >
How do you get an excel macro to refer to a different column each time its run?

Reply  
Thread Tools
islandgirl321's Avatar
Junior Member with 7 posts.
 
Join Date: Nov 2009
17-Nov-2009, 06:49 AM #1
How do you get an excel macro to refer to a different column each time its run?
I need an excel macro to refer to a different column each time I run the same macro. Does anyone know what the syntax is for this?
islandgirl321's Avatar
Junior Member with 7 posts.
 
Join Date: Nov 2009
17-Nov-2009, 07:02 AM #2
If anyone can help that would be amazing as I have to try and get this done before work tomorrow! Ahh!
turbodante's Avatar
Senior Member with 744 posts.
 
Join Date: Dec 2008
Location: GMT UK
17-Nov-2009, 08:48 AM #3
Quote:
Originally Posted by islandgirl321 View Post
I need an excel macro to refer to a different column each time I run the same macro. Does anyone know what the syntax is for this?

Not 100% sure if I understand what you mean. Do you want the macro to select the column from the cell that has been pre-selected by the user?

If so, then this line may help...

Columns(Selection.Column).Select

If not, please restate what you want the macro to do.
turbodante's Avatar
Senior Member with 744 posts.
 
Join Date: Dec 2008
Location: GMT UK
17-Nov-2009, 08:49 AM #4
Welcome to the forum btw.
Rollin_Again's Avatar
Senior Member with 4,273 posts.
 
Join Date: Sep 2003
Location: Atlanta, GA - Planet Earth
Experience: Brilliant When Sober
17-Nov-2009, 10:30 PM #5
Please post your existing code so we can understand what you are trying to achieve.

Regards,
Rollin
Zack Barresse's Avatar
Computer Specs
Distinguished Member with 5,030 posts.
 
Join Date: Jul 2004
Location: Oregon, United States
Experience: I'ma learnin'!
18-Nov-2009, 01:29 AM #6
Hi there, and welcome to the board!

You definitely need to post more information, as has been requested. What would help us is if you gave us a detailed description of the data you have and how it's structured. I.e. headers in range xx:yy, data is from range aa:zz, etc. Also, what it is you are trying to achieve with your macro, the end result. But start point, and end point, as detailed as possible.
islandgirl321's Avatar
Junior Member with 7 posts.
 
Join Date: Nov 2009
18-Nov-2009, 02:33 AM #7
Thanks guys, sorry. Ill get more info from my computer at home tonight and repost! Thanks
islandgirl321's Avatar
Junior Member with 7 posts.
 
Join Date: Nov 2009
18-Nov-2009, 08:12 AM #8
An example of what I'm trying to do is as follows:

My data is in column C and column A is empty. When I run the macro the first time I want to insert a column to the left of column C so then my data moves to column D. I then want to copy the data column D and past into column C.

The second time I run the Macro I want to do the same as above but start from column D. Column A is still empty, and therefore I want to insert a column to the left of column D so then my data moves to column E. I then want to copy the data column E and past into column D. And so on...............

I therefore I need some sort of looping syntax, refer to an empty column syntax as a starting point if I have to and refer to the next column up from where I started every time the macro is run.

I'm new to all of this.

Please help!!!!
bomb #21's Avatar
Distinguished Member with 8,082 posts.
 
Join Date: Jul 2005
Location: The void AKA edge of the Fens
Experience: I bent my wookie :(
18-Nov-2009, 08:37 AM #9
Are you saying you want the code to operate on the first free column?
islandgirl321's Avatar
Junior Member with 7 posts.
 
Join Date: Nov 2009
18-Nov-2009, 09:09 AM #10
yes! Can i also tell it what the first free column is?

sorry if im confusing!
islandgirl321's Avatar
Junior Member with 7 posts.
 
Join Date: Nov 2009
18-Nov-2009, 09:10 AM #11
It will also move down one column every time, but the new column will always be empty
bomb #21's Avatar
Distinguished Member with 8,082 posts.
 
Join Date: Jul 2005
Location: The void AKA edge of the Fens
Experience: I bent my wookie :(
18-Nov-2009, 09:28 AM #12
"I want to insert a column to the left of column C so then my data moves to column D. I then want to copy the data column D and past into column C."

If I read that right then copying the last column one column to the right of the last column gives the same result but goes about it more methodically.

Sub test()
LastColumn = ActiveSheet.UsedRange.Columns(ActiveSheet.UsedRange.Columns.Count).Column
Columns(LastColumn).Copy Cells(1, LastColumn + 1)
End Sub


(adapted from ozgrid)
__________________
"Love All The People."
Bill Hicks, 1961 - 1994 -- R.I.P.
islandgirl321's Avatar
Junior Member with 7 posts.
 
Join Date: Nov 2009
18-Nov-2009, 09:43 AM #13
Thanks, I'll have a go at that now and let you know how it goes! Thanks for your time!
Reply

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.

Search Tech Support Guy

Find the solution to your
computer problem!




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who want to help you solve your computer problems. See our Welcome Guide to get started.
Thread Tools



Facebook Facebook Twitter Twitter TechGuy.tv TechGuy.tv Mobile TSG Mobile
You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 09:33 PM.
Copyright © 1996 - 2011 TechGuy, Inc. All rights reserved.

Powered by Cermak Technologies, Inc.