Results 1 to 10 of 10

VBA button - reference to another sheet

Threaded View

Baoli VBA button - reference to... 02-29-2012, 10:50 AM
arlu1201 Re: VBA button - refrens to... 02-29-2012, 11:08 AM
Baoli Re: VBA button - refrens to... 02-29-2012, 01:20 PM
arlu1201 Re: VBA button - refrens to... 02-29-2012, 02:29 PM
Baoli Re: VBA button - refrens to... 02-29-2012, 03:19 PM
Richard Buttrey Re: VBA button - refrens to... 03-01-2012, 09:57 AM
Baoli Re: VBA button - refrens to... 03-01-2012, 04:27 PM
JBeaucaire Re: VBA button - reference to... 03-02-2012, 12:39 PM
  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.

    Sub RandomPlace_Click()
    Dim ListCount As Integer, num
    Dim RandomNumber As Integer
    Dim rng As Range
    
    Set rng = Sheets("Rådata-Restaurang").Range("B3:B20")
    ListCount = rng.Count
    RandomNumber = Int(ListCount * Rnd + 1)
    ActiveSheet.Range("B11").Select
    ActiveSheet.Range("B11").Value = ActiveCell.Offset(RandomNumber - 1, 0).Value
    End Sub
    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.

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