+ Reply to Thread
Results 1 to 28 of 28

VBA referring to a different sheet, automatically fill cell based on content of other cell

  1. #1
    Registered User
    Join Date
    02-04-2013
    Location
    Buffalo, New York
    MS-Off Ver
    Excel 2010
    Posts
    27

    VBA referring to a different sheet, automatically fill cell based on content of other cell

    There are 3 tabs that are used in the worksheet: For Sales, itmof, and itbof

    I need a VBA that will be embedded on the itmof tab but will effect the itbof tab.
    On the itbof tab I need column C to be automatically filled with a letter A only if there is any kind of value (letters or numbers) in column A, starting with row 2 and below. I also need need column T to be automatically filled with the letter N only if there is any kind of value (letters or numbers) in column A, starting with row 2 and below.
    Last thing, I need column I to be automatically filled with (the value in column L multiplied by 1.08) only if there is a value in column L, starting at row 2 and below.

    So there's no confusion, this VBA will be going on my itmof tab because I need it linked to a button on that sheet, but all these changes should only effect the itbof tab.

    Slowly but surely, learning VBA!

    Thanks

  2. #2
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,821

    Re: VBA referring to a different sheet, automatically fill cell based on content of other

    Could you post a copy of your file? It would make it easier to help.

  3. #3
    Registered User
    Join Date
    02-04-2013
    Location
    Buffalo, New York
    MS-Off Ver
    Excel 2010
    Posts
    27

    Re: VBA referring to a different sheet, automatically fill cell based on content of other

    Here is a copy of the file.

    Thanks
    Attached Files Attached Files

  4. #4
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,821

    Re: VBA referring to a different sheet, automatically fill cell based on content of other

    Will the data in the itbof tab be entered manually?

  5. #5
    Registered User
    Join Date
    02-04-2013
    Location
    Buffalo, New York
    MS-Off Ver
    Excel 2010
    Posts
    27

    Re: VBA referring to a different sheet, automatically fill cell based on content of other

    No sir, it will be brought over from the For Sales tab when you hit the Copy Data button on the itmof tab.

  6. #6
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,821

    Re: VBA referring to a different sheet, automatically fill cell based on content of other

    Place this code in the worksheet module for Sheet("itbof")... not in Sheet("itmof"). When you click the 'Copy Data' button and then select Sheet("itbof"), your columns should automatically update.

    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    02-04-2013
    Location
    Buffalo, New York
    MS-Off Ver
    Excel 2010
    Posts
    27

    Re: VBA referring to a different sheet, automatically fill cell based on content of other

    OK, this is progress... It only works when I press the copy data button first, and then paste this code in the itbof tab. If I leave this code pasted in the itbof tab it will always give me an error before I press the copy data button. Is there anyway to get this to only run after I press the copy data button?

    Thanks

  8. #8
    Registered User
    Join Date
    02-04-2013
    Location
    Buffalo, New York
    MS-Off Ver
    Excel 2010
    Posts
    27

    Re: VBA referring to a different sheet, automatically fill cell based on content of other

    OK, I'll rephrase this, I did some more testing, and the only time it errors out is if I switch over to the itbof tab before I hit the copy data button, other than that it works great. To make it "dummy proof" is there any way to just make it run after I hit the itbof tab? This way it doesn't matter if we accidentally switch to that tab first before the copy data button is pressed...

    Thanks, I appreciate everything you've done so far!

  9. #9
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,821

    Re: VBA referring to a different sheet, automatically fill cell based on content of other

    I would like to make a suggestion. First, remove the code from the worksheet module and put it into a regular module and change the name of the macro so that it's not a Worksheet_Activate event. Then you can run the macro by assigning it to a button on either worksheet or you can call the macro from your "Copy Data" macro. If you call it from the "Copy Data" macro, it will complete the "itbof" sheet automatically when it completes the "itmof" sheet. If you want to keep the two tasks separate, then assign it to a button. I hope that helps.

  10. #10
    Registered User
    Join Date
    02-04-2013
    Location
    Buffalo, New York
    MS-Off Ver
    Excel 2010
    Posts
    27

    Re: VBA referring to a different sheet, automatically fill cell based on content of other

    I tried both of those suggestions and neither one worked for me. I think it's having a problem calling the sub if it's in a different sheet other than my itmof tab and vice versa, if the sub is in my itmof tab and I assign it to copy data macro, then it errors out a certain line in the sub...

    Thanks

  11. #11
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,821

    Re: VBA referring to a different sheet, automatically fill cell based on content of other

    Try this code. It should work regardless of where you call it from.

    Please Login or Register  to view this content.

  12. #12
    Registered User
    Join Date
    02-04-2013
    Location
    Buffalo, New York
    MS-Off Ver
    Excel 2010
    Posts
    27

    Re: VBA referring to a different sheet, automatically fill cell based on content of other

    Fantastic! That worked beautifully. I hate to be a pest but in this line:

    Please Login or Register  to view this content.
    Is there any way you could write something in there to Round to 5 decimal places if the number goes to 6 decimal places or more?

    Thanks

  13. #13
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,821

    Re: VBA referring to a different sheet, automatically fill cell based on content of other

    I'm glad that it worked out for you! I think that you can more easily do the rounding off by formating the column as a number with 5 decimal places instead of using VBA.

  14. #14
    Registered User
    Join Date
    02-04-2013
    Location
    Buffalo, New York
    MS-Off Ver
    Excel 2010
    Posts
    27

    Re: VBA referring to a different sheet, automatically fill cell based on content of other

    I did try that and it doesn't work for what we need, it will still show up as 6 or however many decimal places it is if you click on the cell. It will then error out when we try to upload the spreadsheet to our database because of the extra decimal places. That's kind of why we need the VBA to take care of that before it's entered in the cell...

  15. #15
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,821

    Re: VBA referring to a different sheet, automatically fill cell based on content of other

    Try adding these lines:
    Please Login or Register  to view this content.
    "
    below this line:
    Please Login or Register  to view this content.

  16. #16
    Registered User
    Join Date
    02-04-2013
    Location
    Buffalo, New York
    MS-Off Ver
    Excel 2010
    Posts
    27

    Re: VBA referring to a different sheet, automatically fill cell based on content of other

    OK, I tried this and it did not work, every time I ran it, excel tried to use the I column in itmof and not itbof. It still didn't do anything in the I column of itmof because there is no data there but every time I ran it the entire I column in itmof was highlighted. I think if you can get it to go to the itbof tab, then column I will successfully be rounded to 5 decimal places!

  17. #17
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,821

    Re: VBA referring to a different sheet, automatically fill cell based on content of other

    OK. Try replacing this line:

    Please Login or Register  to view this content.
    with this line:
    Please Login or Register  to view this content.

  18. #18
    Registered User
    Join Date
    02-04-2013
    Location
    Buffalo, New York
    MS-Off Ver
    Excel 2010
    Posts
    27

    Re: VBA referring to a different sheet, automatically fill cell based on content of other

    Almost, I replaced that line and it is pointing at the I column in the itbof tab now but it kicked back a Microsoft Visual Basic for Application.... error window with a 400 in the middle of the error window and nothing else...

  19. #19
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,821

    Re: VBA referring to a different sheet, automatically fill cell based on content of other

    My apologies. I don't know what's going on because in my tests using the file you sent me it works properly. I can't reproduce any error.

  20. #20
    Registered User
    Join Date
    02-04-2013
    Location
    Buffalo, New York
    MS-Off Ver
    Excel 2010
    Posts
    27

    Re: VBA referring to a different sheet, automatically fill cell based on content of other

    Shoot! lol

    Did you assign this sub to the Copy Data macro on itmof and it still worked for you? Can you send me the code that is working for you so I can test with it and see if I get the same results?

    Thanks

  21. #21
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,821

    Re: VBA referring to a different sheet, automatically fill cell based on content of other

    Here is the code. Just put it into a regular module and run it form there.

    Please Login or Register  to view this content.

  22. #22
    Registered User
    Join Date
    02-04-2013
    Location
    Buffalo, New York
    MS-Off Ver
    Excel 2010
    Posts
    27

    Re: VBA referring to a different sheet, automatically fill cell based on content of other

    OK, thanks for supplying this code I thought's what it was. I tried it again and got the same 400 error pop up. Everything else works but column I on itbof doesn't get populated anymore because of the error. I have attached a copy of my workbook with the updated code in it that I'm using so you can open it and see what I'm talking about.

    Thanks!
    Attached Files Attached Files

  23. #23
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,821

    Re: VBA referring to a different sheet, automatically fill cell based on content of other

    The problem was that you had the macros in the worksheet module instead of a regular module. I moved the macros into Module3 and changed the 'Copy Data' button link to the new location of the macro. Your 'copydata' macro now runs and then calls the 'FillColumnsitbof' so both operations are run one after the other. If you want to run them separately, delete the line:
    Please Login or Register  to view this content.
    in the 'copydata' macro and assign the 'FillColumnsitbof' macro to a separate button. The attached file has all the changes. Hopefully, everything is OK now.
    Attached Files Attached Files

  24. #24
    Registered User
    Join Date
    02-04-2013
    Location
    Buffalo, New York
    MS-Off Ver
    Excel 2010
    Posts
    27

    Re: VBA referring to a different sheet, automatically fill cell based on content of other

    I don't think your attached file made it's way over, I don't see it anywhere. I'm anxious to test it though and see what your talking about in the VBA! It's easier for to visual see it and learn it. If you could please send the updated file again that would be great!

    Thanks!

  25. #25
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,821

    Re: VBA referring to a different sheet, automatically fill cell based on content of other

    When I open the thread, the file is there. Have another look. If you still can't find it, let me know and I'll re-send it.

  26. #26
    Registered User
    Join Date
    02-04-2013
    Location
    Buffalo, New York
    MS-Off Ver
    Excel 2010
    Posts
    27

    Re: VBA referring to a different sheet, automatically fill cell based on content of other

    Worked like a charm. I love you!

    Thanks again for all your help Mumps1!

  27. #27
    Registered User
    Join Date
    02-04-2013
    Location
    Buffalo, New York
    MS-Off Ver
    Excel 2010
    Posts
    27

    Re: VBA referring to a different sheet, automatically fill cell based on content of other

    Worked like a charm. I love you!

    Thanks again for all your help Mumps1!

  28. #28
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,821

    Re: VBA referring to a different sheet, automatically fill cell based on content of other

    It was my pleasure. I'm glad we finally got it to work for you!

+ 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