+ Reply to Thread
Results 1 to 13 of 13

Macro to move any selected cell to a specific column on the same row

  1. #1
    Registered User
    Join Date
    10-28-2013
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    6

    Macro to move any selected cell to a specific column on the same row

    Hi,
    I'm sure this is easy but I can't seem to find the answer. I'd like a macro that will take the data in any cell I have selected and move it to a specific column in the same row it was selected on.
    Thank you for your time!
    Jonah

    So select A1 and have it go to G1
    or I can select B2 and have it go to G2
    or I can select C3 and have it go to G3
    or I can select D4 and have it go to G4

    Any cell I select and run the macro on the data always goes to column G on the same row

  2. #2
    Forum Expert
    Join Date
    06-09-2010
    Location
    Australia
    MS-Off Ver
    Excel 2013
    Posts
    1,714

    Re: Macro to move any selected cell to a specific column on the same row

    Hi
    try this

    Please Login or Register  to view this content.
    Note - if you have more than one cell selected in the same row, the macro will only copy the last value. Let me know if you want more than one value copied into the cell in column G if more than one cell is selected in that row.
    Last edited by NickyC; 10-28-2013 at 11:46 PM.

  3. #3
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Macro to move any selected cell to a specific column on the same row

    @ NickyC,

    Nice work. You could also use your code in the Worksheet Change Event.

    Please Login or Register  to view this content.
    Please consider:

    Be polite. Thank those who have helped you. Then Click on the star icon in the lower left part of the contributor's post and add Reputation. Cleaning up when you're done. If you are satisfied with the help you have received, then Please do Mark your thread [SOLVED] .

  4. #4
    Forum Expert
    Join Date
    06-09-2010
    Location
    Australia
    MS-Off Ver
    Excel 2013
    Posts
    1,714

    Re: Macro to move any selected cell to a specific column on the same row

    Thanks Winon,
    you're right, that will make things easier if Jonah wants to move the value each time the cell changes.

  5. #5
    Registered User
    Join Date
    10-28-2013
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: Macro to move any selected cell to a specific column on the same row

    Thank you NickyC and Winon!

    NickyC: The code you wrote copies the data to the column. Is there an easy to change that so that it moves the data?

    Winon: When I paste the code you wrote into the Visual Basic module in Excel the macro doesn't show up in the run macros window. If I modify the first line to be Sub Worksheet_Change() it will show up but when I run it Excel says there is an error in the line If Target.Rows.Count > 1 Then Exit Sub. I am very new to macros and don't have a good understanding of what each line of code means or the different ways to go about running macros. I'm sure this is an error on my side. Your further input would be greatly appreciated. Just in case it matters, I'm running Excel 2010 in Windows 7

    One other question, within this same macro is it easy to add the ability to move the data up or down a row in the final column? So, always same column but the next row up.

    Finally, thank you for helping me on this. Each time I use a macro and see what it does I am learning how they work and the commands that are used to do different operations. Probably not the most efficient way to learn but it seems to be working for simple operations.

    Thanks again.

  6. #6
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Macro to move any selected cell to a specific column on the same row

    Hello Jonah Mulski,

    Welcome to the Forum.

    Thank you for the feedback.

    ...the ability to move the data up or down a row in the final column? So, always same column but the next row up.
    It can be done, but then your data in Column G will be out of line with the data on the left.i.e. Either one row down, or one row up. Is that what you want?

  7. #7
    Registered User
    Join Date
    10-28-2013
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: Macro to move any selected cell to a specific column on the same row

    Hi Winon,
    At times yes. I know how to make a macro that will move data from the cell it is in to another cell relative to the original so when I asked the original question I figured I could just run the macro you originally helped me with and then run another macro if I needed to move the data up or down within the column. But if one macro could do both that would be even better.
    Again, thank you for your time and information.
    Jonah

  8. #8
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Macro to move any selected cell to a specific column on the same row

    Hello Jonah Mulski,

    Let us take it one step at a time. First, please try the attached sample Workbook, and see if it works for you.

    You are not required to "Fire" any Macro since the Code is "attached" the the Sheet itself, within the Sheet_Change event.

    To view the Code, Right-Click on the Sheet Tab, and select View Code.
    Attached Files Attached Files

  9. #9
    Registered User
    Join Date
    10-28-2013
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: Macro to move any selected cell to a specific column on the same row

    Hi Winon,
    The file you attached shows what I'd like to be able to do.
    In your example file the original data is copied to column G but I'd like it to be cut and pasted to column G.
    By "fire" a macro do you mean run it? How would I run this macro if I don't see it in the run macro window?
    Sorry for the dumb questions...

  10. #10
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Macro to move any selected cell to a specific column on the same row

    Hi Jonah Mulski,

    You won't see it in a Macro, because it is not a standard module. It is "Hidden Behind" the Sheet.

    Replace the Code in the Workbook with the Code posted below. It does the same as "Cut and Paste", as far as values are concerned. If you have other formats with the cells like borders, bold font, interior color etc., then we shall have to change the Code. But then again it would also replace any other formats you may have in Column G.

    Please Login or Register  to view this content.

  11. #11
    Registered User
    Join Date
    10-28-2013
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: Macro to move any selected cell to a specific column on the same row

    Okay, this is the function I would like to preform but I only want it to happen on a cell I select and run the macro on. I will be using this to make the task of moving addresses much more efficient. I attached an example of how it will be used. The example shows how the data is imported, somewhat random as to which row the address, city and state end up on (terrible way to import but I don't have control over the importing format). Once I have it in Excel I move the address over to the columns named "Address Line 1", "Address Line 2"...
    So I would like to be able to select a cell and use a keyboard shortcut to run the macro so it's contents move to the appropriate column. For example, B2 would move to E2 and B3 would go to F3.
    NickyC's code worked great, but it copies the data. Like I mentioned, I need it to cut and paste.
    Thank you for sticking with me on this, I deeply appreciate it.
    Attached Files Attached Files

  12. #12
    Forum Expert
    Join Date
    06-09-2010
    Location
    Australia
    MS-Off Ver
    Excel 2013
    Posts
    1,714

    Re: Macro to move any selected cell to a specific column on the same row

    Hi Jonah
    if you want to delete the contents of the active cell as well as copy the contents to column G, try this:

    Please Login or Register  to view this content.

  13. #13
    Registered User
    Join Date
    10-28-2013
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: Macro to move any selected cell to a specific column on the same row

    NickyC, this works perfect. Thank you!
    Winon, thank you for the time you took yesterday to work with me on this.

    Again, thank you both for your time and information. I really appreciate it!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Macro/VBA to move specific data from one column to another (without duplicates)
    By JezVanderBrown in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 10-29-2013, 06:36 AM
  2. Insert Date When Cell in specific column is selected
    By G33kman in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-13-2013, 08:19 PM
  3. Find Duplicates and move a selected cell to another column
    By scottie72 in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 08-24-2012, 09:33 AM
  4. Selected cell move one column to the right
    By marksuza in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-12-2009, 04:26 AM
  5. Replies: 2
    Last Post: 03-13-2006, 01:10 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1