+ Reply to Thread
Results 1 to 9 of 9

Understanding VBA to transfer to another workbook.

  1. #1
    Forum Contributor Marvo's Avatar
    Join Date
    01-15-2009
    Location
    Northampton, England
    MS-Off Ver
    Excel 2021
    Posts
    990

    Understanding VBA to transfer to another workbook.

    Hi, I "lost" a workbook a few years which some helpful gentleman had set up VBA to work out some complex questions. Since then I've built a new similar one with no VBA. After coming across an old hard drive I've found the older workbook with the VBA still working perfectly. I'd love to copy it to the new workbook but A) I don't understand VBA and B) some things in the new workbook have been moved, data increased, columns added etc. I wondered if I posted the VBA on here, someone might explain to me what its doing? There is just 3 modules. If I can work out what it is looking at I may be able to chnage the References and get it working in the new workbook. Many thanks.

    Module 1

    Please Login or Register  to view this content.
    Module 2
    Please Login or Register  to view this content.
    Module 3

    Please Login or Register  to view this content.
    Last edited by Marvo; 03-20-2024 at 03:08 PM.

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

    Re: Understanding VBA to transfer to another workbook.

    It's not possible to give you a really meaningful answer without the file, because we don't know what any of the data references mean.

    UpdateGames doesn't do much of anything. If cell W1 contains a value, it has no effect. If W1 has a formula, it will replace the formula with the value that results from that formula. And that is a really clunky way to do it. Cleaner, without needing a variable
    Please Login or Register  to view this content.
    Macro1 inserts a formula into whatever cell is currently selected by the user. If the cell in the column to the left is blank the formula return a null string. Otherwise it counts on sheet ALL the number of times the value in the same row number and column 23 columns to the right of the currently selected cell is not equal to the cell to the left and also the next row down in the same column is equal to the cell to the left. I find this confusing and can't imagine the value of such a formula. I would want to see the file to understand better what's going on. (I would have used COUNTIFS for this but if this is old code it may not have been available.)

    Macro2 and 3 do the same thing as Macro1, just using different columns.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Forum Contributor Marvo's Avatar
    Join Date
    01-15-2009
    Location
    Northampton, England
    MS-Off Ver
    Excel 2021
    Posts
    990

    Re: Understanding VBA to transfer to another workbook.

    Thank you for your response.

    W1 was n empty box that you placed a number in to get information. That is now on a different page, now H5562.

    I've no idea what or where R1C is.

    Sadly my knowledge of VBA is very limited, just managed to construct some to do basic sorts. I could transfer all the new workbook on to the old one as the VBA is working perfectly on there (doing its job) but that would take up an awful lot of time and with extra rows, columns, it probably wouldn't work anyway because the references wouldn't be the same.

    The new book is 3281kb so too large to go on here. The old one, despite having less data is even bigger which I don't quite understand, guess that must be to do with the VBA.

    Very frustrating. I have managed to do the same job using formula but needed dozens of helper columns.

    I could put them on one drive to share but I know a lot of people don't like using that.

    Mnay thanks for your assistance.

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

    Re: Understanding VBA to transfer to another workbook.

    R1C1 is another format for writing cell references in a formula.

    The more common method is called A1. The column is first as letters, then the row as numbers

    A1
    BD432

    Those are relative references. If you put those into a formula, then copy the formula to another cell, the references will be updated to refer to cells in the same relative position as the cell containing the formula. To make them absolute, start with a $

    $A1
    A$1
    $A$1

    If you copy to another cell, the part preceded by a $ will not change.

    R1C1 is a different format for doing the same thing. Instead of column letters, it uses numbers. R gives the row number, C gives the column number. These are absolute addresses.

    R1C1 = $A$1
    R432C56 = $BD$432

    To make the references relative, enclose the numbers in [brackets]

    R1C[1] = $A1
    R[1]C1 = A$1
    R[1]C[1] = A1

  5. #5
    Forum Contributor Marvo's Avatar
    Join Date
    01-15-2009
    Location
    Northampton, England
    MS-Off Ver
    Excel 2021
    Posts
    990

    Re: Understanding VBA to transfer to another workbook.

    Thank you again. I'll see if I can discover what the VBA is referring too, then maybe I can construct the VBA in the newer workbook.

    Note: The VBA is 4 years old.

  6. #6
    Forum Contributor Marvo's Avatar
    Join Date
    01-15-2009
    Location
    Northampton, England
    MS-Off Ver
    Excel 2021
    Posts
    990

    Re: Understanding VBA to transfer to another workbook.

    Can I ask one question before I get into this. In the old workbook you can put a number, lets say 5 into a cell. The workbook then looks for for example the amount of times the team has won 5 games in a row (sometimes with criteria like home or league). It then gives you an answer, so lets say the team has won 5 in a row 300 times. Then in V26 it gives you the date of when this last occurred. I can't see where V26 is mentioned in the VBA?

  7. #7
    Forum Contributor Marvo's Avatar
    Join Date
    01-15-2009
    Location
    Northampton, England
    MS-Off Ver
    Excel 2021
    Posts
    990

    Re: Understanding VBA to transfer to another workbook.

    Actually, scratch that, it looks like I can achieve the same result with formula without the VBA. Sorry to have bothered you.

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

    Re: Understanding VBA to transfer to another workbook.

    No bother at all. That's what we're here for.

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

    Re: Understanding VBA to transfer to another workbook.

    If your question has been answered please mark your thread as "Solved" so that members will know by looking at the thread title that your problem is solved. Go to the menu immediately above your first post to the thread and click on Thread Tools. From the dropdown menu select "Mark this thread 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. Workbook to workbook info transfer with dynamic names on button
    By jackers15 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-15-2017, 08:12 AM
  2. Replies: 4
    Last Post: 04-04-2016, 04:09 AM
  3. [SOLVED] Transfer Data from a Workbook to diff sheets on another workbook
    By jineson23 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-05-2016, 03:00 AM
  4. Replies: 3
    Last Post: 02-21-2014, 09:05 AM
  5. [SOLVED] Error 1004 when trying to modify and transfer data from one workbook to a new workbook
    By jecook in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-29-2013, 02:51 AM
  6. Transfer Data from one workbook to worksheets in a closed workbook by criteria
    By jftapel in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-21-2012, 05:23 AM

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