+ Reply to Thread
Results 1 to 5 of 5

transfer data sheet1 to sheet2 VBA problem

  1. #1
    Registered User
    Join Date
    12-14-2021
    Location
    kuching
    MS-Off Ver
    home: Excel 365, working: Excel 2016
    Posts
    50

    transfer data sheet1 to sheet2 VBA problem

    hi, I am really novices in VBA. Hopefully someone can help me to solve my problem.

    I take this vba code from some where in youtube.

    I try to copy and paste specific Worksheet Range Data from "Sheet1" to "Sheet2" based on condition in "Sheet2" which is if the
    "Sheet2" has the same id number then it will be paste in spesific range of data only.

    This is the coding, but it cannot transfer the data. I don't know why. May be my friend here can give me the idea how to improve the coding.
    Thank you very much.
    --------------------
    Please Login or Register  to view this content.
    --------------------
    TRANSFER sheets1 to sheets2 Sample.xlsm

    regard,
    habib
    Last edited by habids; 06-16-2023 at 10:22 AM.

  2. #2
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: transfer data sheet1 to sheet2 VBA problem

    Hi habib, thanks for adding the code tags. My answer is 2 part:

    The reason your code does nothing is that this line:
    Please Login or Register  to view this content.
    sets "lasrow2", but your loop is 2 to lastrow2 (which is 0)

    But I also wanted to mention that if the data set is big, doing a double loop could take longer than something like this:

    Please Login or Register  to view this content.
    Last edited by Arkadi; 06-16-2023 at 12:16 PM.
    Please help by:

    Marking threads as closed once your issue is resolved. How? The Thread Tools at the top
    Any reputation (*) points appreciated. Not just by me, but by all those helping, so if you found someone's input useful, please take a second to click the * at the bottom left to let them know

    There are 10 kinds of people in this world... those who understand binary, and those who don't.

  3. #3
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,724

    Re: transfer data sheet1 to sheet2 VBA problem

    Quote Originally Posted by Arkadi View Post
    The reason your code does nothing is that this line:
    Please Login or Register  to view this content.
    sets "lasrow", but your loop is 2 to lastrow2 (which is 0)
    I strongly recommend to everyone that they use Option Explicit and declare variables. Doing so prevents a lot of bugs and runtime errors. If Option Explicit were used here, this error would have been flagged by the compiler.
    Jeff
    | | |·| |·| |·| |·| | |:| | |·| |·|
    Read the rules
    Use code tags to [code]enclose your code![/code]

  4. #4
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: transfer data sheet1 to sheet2 VBA problem

    Very good point @6StringJazzer! I forgot to point that part out, but use it most of the time (I do forget once in a while).

  5. #5
    Registered User
    Join Date
    12-14-2021
    Location
    kuching
    MS-Off Ver
    home: Excel 365, working: Excel 2016
    Posts
    50

    Re: transfer data sheet1 to sheet2 VBA problem

    wow. I am really careless when reading the code.
    Really appreciate to Arkadi and 6StringJazzer.
    thank you very much. Its solve my pain.

+ 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. Can Excel transfer data From sheet1 to Sheet2?
    By BM2006 in forum Excel General
    Replies: 5
    Last Post: 03-25-2016, 04:55 AM
  2. Transfer Data from Sheet1 to Sheet2
    By smilan in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 03-23-2015, 03:52 PM
  3. Transfer entered data from Sheet1(REQUISIÇÃO) to Sheet2
    By segun1ng in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 07-29-2014, 03:48 PM
  4. transfer current data from Sheet1 to Sheet2 via a button on Sheet1
    By BJB_88 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 06-08-2014, 06:02 AM
  5. I want to transfer data from SHEET1 to SHEET2
    By hesham63 in forum Excel General
    Replies: 4
    Last Post: 07-30-2011, 12:28 PM
  6. Transfer data from sheet1 to sheet2 and sheet3
    By vbosmiya in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 03-21-2007, 11:42 PM
  7. Transfer data from sheet1 to sheet2
    By Tommy in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 05-11-2005, 02:06 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