+ Reply to Thread
Results 1 to 4 of 4

My macro is copying data in error

  1. #1
    Registered User
    Join Date
    12-02-2010
    Location
    Los Angeles
    MS-Off Ver
    Excel 2003
    Posts
    21

    My macro is copying data in error

    I am trying to create a macro to use the data "Text to column" function to convert a column of data to text. (Just so you understand how I'm creating the macro - I highlight the column (A) and hit ALT DEWNNTF)

    A B C D
    INV USER MNO SCRNO
    9242852 38026 6966 A2046443
    9243250 06046 6948 BS047985
    9243293 20123 7594 AM051514
    9243282 31153 2822 AU045045
    9243280 04218 2552 BU122874
    9243260 02031 1223 A0232935

    What ends up happening after I record the macro (say on column A) and try it on another column (say B) is that the data from column B is copied to column A. If I do column C, then A has the data of column C.

    A B C D
    USER USER MNO SCRNO
    38026 38026 6966 A2046443
    38026 06046 6948 BS047985
    20123 20123 7594 AM051514
    31153 31153 2822 AU045045
    04218 04218 2552 BU122874
    02031 02031 1223 A0232935

    I don't know if it's the way I'm creating the macro, but I'm not sure why it's copying the infomation and not sure how to create the mcro correctly to do what I want.

    Can anyone help?
    Last edited by steinfm; 12-02-2010 at 09:19 PM.

  2. #2
    Forum Contributor
    Join Date
    07-05-2006
    Location
    Canada
    MS-Off Ver
    2003, 2007
    Posts
    581

    Re: My macro is copying data in error

    Hi,

    The macro recorder is good, but it does have limitations. In this case, I think what you are looking for could be fixed by re-recording the macro in a slightly different fashion. (Alternatively, you can look at the code itself and make a fix)

    To do what you're trying to do, I'd recommend the following steps:
    (A) Highlight the column.
    (B) Enable the Macro Recorder.
    (C) Click the button on the Macro Recorder that says "Relative Reference" (It should be highlighted/enabled).
    (D) Do the Text-To-Columns thing.
    (E) Unclick the "Relative Reference" button and end the macro.

    Then, to use, select a cell in the column in question.

    S
    ------------------------------------------------------------------------------------------
    If you need no more help on the current problem, please mark it as "Solved". It saves time
    as many of us will look at threads if they are not marked as "Solved".

    The instructions on how to do this are found in the Forum Rules thread that is at top of every forum.
    (Currently you'll have to look at point #9.)
    ------------------------------------------------------------------------------------------

  3. #3
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: My macro is copying data in error

    Hi,

    It's always difficult to guess what you've done which is why an example workbook is worth a thousand words, but probably because you changed the "Columns("A:A").Select" bit to "Columns("B:B").Select", but you didn't change the "Destination:=Range("A1")".

    But a more fundamental question is why, if you've already parsed a single column A into 4 columns, do you want to parse column B? If this needs to be split further why not make sure the original parse statement handles it.

    Regards
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  4. #4
    Registered User
    Join Date
    12-02-2010
    Location
    Los Angeles
    MS-Off Ver
    Excel 2003
    Posts
    21

    Re: My macro is copying data in error

    Thank you. That worked.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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