+ Reply to Thread
Results 1 to 10 of 10

VBA button - reference to another sheet

  1. #1
    Registered User
    Join Date
    02-22-2012
    Location
    Sweden
    MS-Off Ver
    Excel 2010
    Posts
    13

    VBA button - reference to another sheet

    Hi,
    Sorry if this question is abit to "simple" to answor, but im extremly new at this - so if someone has time to help i would be very thankful!

    OBS :Code below.
    What i want to do is to press a button that randomly chooses a "restaurang" from a list (thats on another sheet) and puts it in a cell (on the current sheet). All in the same excel file, just diffrent sheets. So in the sheet with a list of "restaurangs" theres a.. list which it should choose from.

    Below is the code. And under i explain what the problem is.

    Please Login or Register  to view this content.
    I believe that, since i didnt make the code. that the "set rng" doesnt understand that i want to set the range in another sheet since now it randomly picks a cell between b3 and b20 in the CURRENT sheet and puts it in B11, instead of picking the ones from the OTHER sheet.

    Any ideas :/ ? Would be extremly greatful!
    Last edited by Baoli; 03-05-2012 at 01:14 PM.

  2. #2
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: VBA button - refrens to another sheet

    You just need to change this row
    Please Login or Register  to view this content.
    Since i do not have a sample file to look at, all you need to do is change the "Radata-Restaurang" to the name of the "OTHER" sheet.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  3. #3
    Registered User
    Join Date
    02-22-2012
    Location
    Sweden
    MS-Off Ver
    Excel 2010
    Posts
    13

    Re: VBA button - refrens to another sheet

    It already refers to the other sheet. "Rådata-Restaurang" is the other sheet. "Val" is the current sheet.

  4. #4
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: VBA button - refrens to another sheet

    This is what is messing up the code -
    Please Login or Register  to view this content.
    You need to find the address of the cell that contains the random number and then offset it by 1 column.

  5. #5
    Registered User
    Join Date
    02-22-2012
    Location
    Sweden
    MS-Off Ver
    Excel 2010
    Posts
    13

    Re: VBA button - refrens to another sheet

    =(...
    I dont get it. So sorry mates. And thanks so much for the help.
    But what i need is. The button is on the same sheet as i want to randomly get a name to appear (Cell B5 in sheet "Val"). But the LIST is in (("Rådata-Restaurang").Range("B3:B20"))
    So how do i change these 2 last lines to get it to work? =S

    Please help.

  6. #6
    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: VBA button - refrens to another sheet

    Please upload a workbook or a representative cut down copy, anonymised if necessary. It is always easier to advise if we can see your request in its context.

    Show a before and after situation and if it's not blindingly obvious how you have arrived at your results some explanatory notes as well.

    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.

  7. #7
    Registered User
    Join Date
    02-22-2012
    Location
    Sweden
    MS-Off Ver
    Excel 2010
    Posts
    13

    Re: VBA button - refrens to another sheet

    EF showroom.xlsm

    Here is the file (very deletetd from information) but the "button" and code is still there

    Hope it may help,
    I would be EXTREMLY greatful!

    Thanks,
    Baoli

  8. #8
    Forum Expert dangelor's Avatar
    Join Date
    09-06-2011
    Location
    Indiana, USA
    MS-Off Ver
    MS365 V.2406
    Posts
    2,308

    Re: VBA button - refrens to another sheet

    Possibly...
    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    02-22-2012
    Location
    Sweden
    MS-Off Ver
    Excel 2010
    Posts
    13

    Re: VBA button - refrens to another sheet

    Works perfectly sir! Thank you!

  10. #10
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: VBA button - reference to another sheet

    If that takes care of your need, please click EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

+ 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