+ Reply to Thread
Results 1 to 11 of 11

Copying data between sheets

  1. #1
    Registered User
    Join Date
    04-08-2009
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    85

    Copying data between sheets

    I'm using VBA linked to buttons at the end of each row in a worksheet (about 20 rows) to xfer data
    in the relevant row onto another worksheet. The code looks as follows:

    Please Login or Register  to view this content.
    I'm doing that for ten columns. What I'm wondering is, is there a way by passing
    parameters to pass the number of the relevant row to the subroutine so that where
    for instance the code is "Range("A6").Select", that number is inserted next to 'A' and
    used in the program?

    Hope that was clear enough, any help appreciated!

  2. #2
    Valued Forum Contributor
    Join Date
    03-24-2014
    Location
    England
    MS-Off Ver
    Excel 2003 - 2016
    Posts
    575

    Re: Copying data between sheets

    Have a read of: https://www.excelcampus.com/vba/copy...ls-vba-macros/

  3. #3
    Registered User
    Join Date
    04-08-2009
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    85

    Re: Copying data between sheets

    No thks that doesn't do the job...

  4. #4
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,236

    Re: Copying data between sheets

    How bout uploading a sample file depicting the result.
    Good Luck
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the star to left of post [Add Reputation]
    Also....add a comment if you like!!!!
    And remember...Mark Thread as Solved.
    Excel Forum Rocks!!!

  5. #5
    Registered User
    Join Date
    04-08-2009
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    85

    Re: Copying data between sheets

    Quote Originally Posted by sintek View Post
    How bout uploading a sample file depicting the result.
    Yes but the output isn't important - I'm just wondering if there's a more elegant and less
    tedious way to change this particular line/s "Range("A6").Select" etc so that the row number
    can be automatically changed in the code to the correct row. As is I can copy and paste the code to each button
    and go through and manually change all the row numbers - but surely there's a more efficient way to
    do the job?

  6. #6
    Registered User
    Join Date
    04-08-2009
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    85

    Re: Copying data between sheets

    Ok no problem I've figured it out myself (very rusty with VBA) - first declare an int and pass it as follows:

    Please Login or Register  to view this content.

    then remove the range command and replace it with Cells(iRow, 1).Select etc where iRow is the row number and the '1' is the column :


    Please Login or Register  to view this content.

  7. #7
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,527

    Re: Copying data between sheets

    Don't use "Select"
    PreExpiry is spelled different. On purpose?
    What determines which row or column to copy and paste? And to where?
    If you want values only, something like
    Please Login or Register  to view this content.
    is more efficient.
    In my opinion, supplying code that does not do what you want is not very helpful.
    A good explanation what you want goes a long way.
    Of course an attachment with before and after is the best.

  8. #8
    Registered User
    Join Date
    04-08-2009
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    85

    Re: Copying data between sheets

    Quote Originally Posted by jolivanes View Post
    Don't use "Select"
    PreExpiry is spelled different. On purpose?
    What determines which row or column to copy and paste? And to where?
    If you want values only, something like
    Please Login or Register  to view this content.
    is more efficient.
    In my opinion, supplying code that does not do what you want is not very helpful.
    A good explanation what you want goes a long way.
    Of course an attachment with before and after is the best.
    Thanks jolivanes! - I was sure there must be a more elegant way to xfer the data
    but as I said my VBA was too rusty to remember how. (The code I supplied works perfectly
    btw - I copied and pasted some of it after running macros which is why it looks so kludgy.)

    I've used the Cells command btw so that I can used the passed parameter:

    Please Login or Register  to view this content.

  9. #9
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,527

    Re: Copying data between sheets

    In Post #1 you mention
    "about 20 Rows" and "I'm doing that for 10 Columns"
    What is the logic of these cells addresses in both Sheets? Potentially you have to transfer 200 values.
    In Post #8 you have "iRow" but what is "iRow"?

  10. #10
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,527

    Re: Copying data between sheets

    Another possibility maybe.
    Change references, Sheets, iRow etc, where required
    Please Login or Register  to view this content.

  11. #11
    Registered User
    Join Date
    04-08-2009
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    85

    Re: Copying data between sheets

    Quote Originally Posted by jolivanes View Post
    Another possibility maybe.
    Change references, Sheets, iRow etc, where required
    Please Login or Register  to view this content.
    Ah yes arrays - I remember using them years ago when I was using VBA much more
    intensively. There's always more than one way to do things with VBA! I prefer
    your earlier code though as it's clearer and simpler.

    'iRow' is the passed parameter I mentioned - I've put a button at the end of each row, which when
    clicked on passes the row number using iRow to the routine, which then copies the data from that
    row to the other worksheet. Simple and efficient!

    Thanks very much for your help jolivanes, I'll mark this as Solved.

+ 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. copying data to different sheets
    By joseph_pat in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 07-21-2015, 11:32 AM
  2. [SOLVED] copying data between sheets
    By ueoplumb in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 07-07-2015, 05:05 AM
  3. Copying Data Between Sheets
    By irish_goat in forum Excel General
    Replies: 4
    Last Post: 09-05-2013, 09:26 AM
  4. Replies: 17
    Last Post: 02-01-2013, 12:20 PM
  5. copying all data into another sheets
    By albert28 in forum Excel General
    Replies: 3
    Last Post: 06-24-2010, 05:17 AM
  6. Copying Data Between Sheets
    By python023 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-21-2009, 01:33 AM
  7. data copying between sheets
    By etacovda in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 10-17-2008, 05:42 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