+ Reply to Thread
Results 1 to 16 of 16

Can I use a macro to enter Poisson random numbers?

  1. #1
    Registered User
    Join Date
    03-18-2009
    Location
    Cardiff, UK
    MS-Off Ver
    Excel 2007
    Posts
    10

    Can I use a macro to enter Poisson random numbers?

    Hey, I'm sure this has been asked before but I couldn't find it using a quick search so here goes...

    I have a spreadsheet which has a column of 100 Poisson-distributed random numbers (lambda=2) which I generated using Data Analysis -> Random Number Generation in Excel. I want to create a macro to put these numbers in for me. When I tried recording one, it didn't work. Is there a way to do it?

    I can provide more info if needed! Thanks!

  2. #2
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: Can I use a macro to enter Poisson random numbers?

    When I recorded a macro, I got this. It should be possible to adapt, no?
    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    03-18-2009
    Location
    Cardiff, UK
    MS-Off Ver
    Excel 2007
    Posts
    10

    Re: Can I use a macro to enter Poisson random numbers?

    I also got a similar piece of code (I'm using Excel 2007 by the way):

    Please Login or Register  to view this content.
    But when I try running the macro, it gives me an error:

    Run-time error '1004':

    Method 'Run' of object '_Application' failed


    How can I fix this?

  4. #4
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: Can I use a macro to enter Poisson random numbers?

    Copy what the macro recorder throws up:
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    03-18-2009
    Location
    Cardiff, UK
    MS-Off Ver
    Excel 2007
    Posts
    10

    Re: Can I use a macro to enter Poisson random numbers?

    Hi Stephen,

    When I tried copying the line exactly as you entered it, i.e.

    Please Login or Register  to view this content.
    I got an error which said "ATPVBAEN.XLA!Random" could not be found.

    When I changed it to:

    Please Login or Register  to view this content.
    (with an extra 'M' in the filename), as the macro recorded gave me originally, I got the error that I described above:

    Run-time error '1004':

    Method 'Run' of object '_Application' failed


    Any suggestions?

  6. #6
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: Can I use a macro to enter Poisson random numbers?

    Are you using Excel 2003? I think the extra M is for 2007. Have you definitely installed the add-in? Tools > Add-Ins.

  7. #7
    Registered User
    Join Date
    03-18-2009
    Location
    Cardiff, UK
    MS-Off Ver
    Excel 2007
    Posts
    10

    Re: Can I use a macro to enter Poisson random numbers?

    I'm using 2007. Sorry, I've just updated my profile info to reflect that. The Data Analysis stuff is already there in 2007, without me having to install it. I could try to get it to work on one of the college computers which uses Excel 2003, but I would still like it to get it work on my computer at home if I can.

  8. #8
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: Can I use a macro to enter Poisson random numbers?

    This worked for me in 2007. Note the extra "".
    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    03-18-2009
    Location
    Cardiff, UK
    MS-Off Ver
    Excel 2007
    Posts
    10

    Re: Can I use a macro to enter Poisson random numbers?

    I still get an error by using that, but a different one this time:

    Run-time error '1004':

    Application-defined or object-defined error



  10. #10
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: Can I use a macro to enter Poisson random numbers?

    Can you attach a file? I haven't used 2007 much. I thought this might be a simple query to resolve!

  11. #11
    Registered User
    Join Date
    03-18-2009
    Location
    Cardiff, UK
    MS-Off Ver
    Excel 2007
    Posts
    10

    Re: Can I use a macro to enter Poisson random numbers?

    Yeah, I'm only just learning VBA, so maybe I'm doing something basic wrong.

    In this file I have 2 macros, the first is in Sheet 1 and contains the line of code exactly as you typed it in your last post. The other macro is in the module and is what I got by recording. They both produce different error messages when I try to run them.
    Attached Files Attached Files

  12. #12
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: Can I use a macro to enter Poisson random numbers?

    Most odd, both of those work for me.

    Perhaps there is a setting which needs to be tweaked.

    See if somebody with more knowledge of 07 can shed light on this.

    EDIT: there is a 2007 forum here, I suggest you ask there.

  13. #13
    Registered User
    Join Date
    03-18-2009
    Location
    Cardiff, UK
    MS-Off Ver
    Excel 2007
    Posts
    10

    Re: Can I use a macro to enter Poisson random numbers?

    I've figured it out now, I did have to tweak an option in Excel. I had to go to Excel Options > Add-Ins > Manage Excel Add-Ins and then click the "Analysis ToolPak - VBA" box. Previously, only the "Analysis ToolPak" (without the VBA) was selected. Thanks for the help!

  14. #14
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Can I use a macro to enter Poisson random numbers?

    That's not going to give you Poisson variates. You could use this:

    Please Login or Register  to view this content.
    Invoke, for example, as
    Please Login or Register  to view this content.
    Entia non sunt multiplicanda sine necessitate

  15. #15
    Registered User
    Join Date
    03-18-2009
    Location
    Cardiff, UK
    MS-Off Ver
    Excel 2007
    Posts
    10

    Re: Can I use a macro to enter Poisson random numbers?

    Why won't it give me Poisson variates? Surely it should do if I recorded it and selected the Poisson option in Data Analysis?

  16. #16
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Can I use a macro to enter Poisson random numbers?

    My apologies, I assume you're right. I've been generating my own random numbers for a long time, and never used Data Analysis to do so.

+ 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