VBA pick random cell - print

hi,
i want to pick a random cell (containing text)  in a given range.

i used the "randbetween" function in excel, but i am now needing thi
in visual basic.

i found the following vba snipplet, but i don�t understand it, an
can�t implement it in my code:


PHP code
-------------------
    With Range("B1")  
  .FormulaR1C1 = _  
  "=OFFSET(Sheet1!RC[-1],RANDBETWEEN(0,9),0)"  
 
-------------------
it would be great if someone could give me an example of picking 
random cell in the range lets say ("A1:B10")

i would also like to know how to combine two random picks with th
print function.
something like:

Print #1,  (function for random cell1 ("a1:B10")) & (function for rand
cell2 ("C3:C10"))

i hope i described my problem good enough...

thank

--
flashing fran
-----------------------------------------------------------------------
flashing frank's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=1375
View this thread: http://www.excelforum.com/showthread.php?threadid=31984

0
11/23/2004 7:21:55 PM
excel.misc 78881 articles. 5 followers. Follow

2 Replies
719 Views

Similar Articles

[PageSpeed] 59

>>it would be great if someone could give me an example of picking a
random cell in the range lets say ("A1:B10")

Okay, here such a function:

Function RandCell(Rg As Range) As Range
    Set RandCell = Rg.Cells(Int(Rnd * Rg.Cells.Count) + 1)
End Function

and here's a test to satisfy yourself it's working.  I'm sure you can hook 
RandCell into your code.

Sub RandCellTest()
    Dim Counter As Long
    Dim TargetRg As Range
    Application.ScreenUpdating = False
    Set TargetRg = Range("A1:A10")
    TargetRg.ClearContents
    Dim Cell As Range
    For Counter = 1 To 10000
        Set Cell = RandCell(TargetRg)
        Cell.Value = Cell.Value + 1
    Next
End Sub

-- 
Jim Rech
Excel MVP 


0
jrrech (1933)
11/23/2004 8:54:28 PM
thanks works fine  :

--
flashing fran
-----------------------------------------------------------------------
flashing frank's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=1375
View this thread: http://www.excelforum.com/showthread.php?threadid=31984

0
11/24/2004 6:20:30 PM
Reply:

Similar Artilces:

VBA code to say Yes or No if any VBA code is present in ActiveWork
Using XL 2003 & 97 Would like hit Ctrl+Shift+V and have an answer either yes or no as to the presence of Any VBA code in the Active Workbook. I do know that about the VBA editor/Explorer or to press the Run Macro button and get a list from various sources . I would like to stay at the keyboard and process a series of macros including one to let me know if I even need to evoke the VBA explorer. TIA Dennis There is no bootstrap macro to tell you whether you have macros or not. If there were there would be no limit to virus writers. --- HTH, David McRitchie, Microsoft MVP - Excel ...

Automatically copy cell above
Does anyone know how to automatically copy cell above the current cell? I have a long list of employees with account numbers. However, I want to only include employees with 6-xxxxx account numbers. Having blank cells on some of rows with account numbers, I may pull 6-xxxxx account numbers without names after sorting the cells by account numbers. Here is how my spreadsheet looks like: ABDULLAH,MALIK 6-63027-1200 ABROKWA,JOE 2-11932-1100 2-11932-2000 2-11987-1010 2-11987-2000 ACTON,LATOYA 6-63027-1200 ACTON,LYNETTE 2-24001-1400 ...

Exchange randomly sending emails to one user
Hi, We have an Exchange 2003 SP2 server running as part of an SBS 2003 Package. Recently, one user started getting old emails resent to him every few hours. It started off as 10-20 emails at a time and has now built up to over 100. We enabled diagnostic logging but nothing out of the ordinary is showing up and no other errors are returned. Has anyone else experienced this and/or could point me to a troubleshooting path? Thanks. On 19 Jun 2006 05:32:12 -0700, martynda@gmail.com wrote: >Hi, > >We have an Exchange 2003 SP2 server running as part of an SBS 2003 >Package. Recently...

Use VBA to update Access table or Query from Excel
Can I use VBA to update Access table or Query from Excel? Thanks in advance Hi Leungkong, > Can I use VBA to update Access table or Query from Excel? Of course, using ADO or DAO. See: http://www.erlandsendata.no/english/index.php?d=envbadacexportado Regards, Jan Karel Pieterse Excel MVP http://www.jkp-ads.com Hi Jan, Thanks. I think ADO is what I want. But I am not only want to export from excel to access. I want to edit some data in access table. For example, Access has a table "ProductList" I want to use Excel to call the product by "Pro...

VBA and Scheduled task in Outlook
Hi, how can I: a) pull the query from somewhere and send it by e-mail automatically. E.g. I want to take a temperature table from http://www.wunderground.com/history/airport/EHAM/2009/7/10/DailyHistory.html?req_city=NA&req_state=NA&req_statename=NA where 2009/7/10 is the date of yesterday put it into an e-mail and send it automatically each day at 8 o'clock? b) if this is not possible, how can I send an e-mail with the attachment c:\Documents\query20090710.xls each day at 8 o'clock? my boss wants this automatized, I know how to write the VBA code for Excel, but don'...

vba select field
Hi, having a button on a form, is it possible to select only some fields (all from the same table) of the current record instead of all fields? I've tried this code: RunCommand acCmdSelectRecord RunCommand acCmdCopy Forse dipende dei dati nel record. but it selects ALL fields in the form. Thank you. Remigio hi, On 10.04.2010 18:01, remigio wrote: > having a button on a form, is it possible to select only some fields > (all from the same table) of the current record instead of all fields? > I've tried this code: > > RunCommand acCmdSelectRecord &...

VLOOKUP in VBA
On the worksheet I can insert in a cell =VLOOKUP(C5, Hobokee.xls!AcsLow, 2) and it works perfectly, looks up the value in column 2 of the range named AcsLow in the same workbook. But elswhere I want in a macro to lookup the same table and assign the result to a variable BalAmt. BalAmt = VLOOKUP(AccNum, Hobokee.xls!AcsLow, 2) does not work. It gives a function not defined error on Hobokee. If instead of Hobokee I put Workbooks("Hobokee"), it gives function not defined error for VLOOKUP which it changes to VLookup. I have been overVLOOKUP in the Help file and see nothing wrong. W...

Excel VBA/Macro programming for beginners
Hi all, I know a bit VB 6.0 programming. Will it help me to write exce vba/macro(same thing?).can anybody help me by providing some fre websites where i can have informations/codes for VBA/macro. Please tell me how could i make a *command Button * in a cell in th excel sheet -- sdebu_200 ----------------------------------------------------------------------- sdebu_2000's Profile: http://www.officehelp.in/member.php?userid=430 View this thread: http://www.officehelp.in/showthread.php?t=118812 Posted from - http://www.officehelp.i Try David McRitchie's "getting started with mac...

Add a set number to a random entered number
I have to start a vehicle service record and am trying to add the 6000 mile service interval to the mileage at service number. EG. A B C D 1 6000 12000 2 12125 18125 3 18200 24200 etc A is the mileage at service and C is the next service due.I am trying to do this without having a cell with a line of 6000 in it and the formula eg =SUM(A1:B1) in the C cell.Is this possable?Hope some one can help. Hi =A1+6000 HTH. Best wishes Harald "Cyclops" <Cyclops@discussions.microsoft.com> skre...

Turn pc speaker on/off with vba code
Is this possible? Thanks I found something here on how to do it withVBScript. You can probably modify it to work in VBA http://www.pcreview.co.uk/forums/thread-1468591.php -- HTH, Barb Reinhardt "David" wrote: > Is this possible? > Thanks Thanks Barb I'll have a go (I need to improve my web searching skills) "Barb Reinhardt" wrote: > I found something here on how to do it withVBScript. You can probably modify > it to work in VBA > > http://www.pcreview.co.uk/forums/thread-1468591.php > -- > HTH, > ...

How do I protect specific cells from changes in Excel?
Please can someone help me. How do I protect specific cells from changes in Excel? I have a spreadsheet that I would like users to only be able to change certain cells, the others need to be protected from change Go to Format>Cells. On the Protection tab, uncheck the "Locked" box for any cell you want to be editable. After you protect the document, the user will only be able to edit the cells you unlock. "LarryH" <LarryH@discussions.microsoft.com> wrote in message news:2E8A5FD8-A990-4181-9842-19B007C88F71@microsoft.com... > Please can someone help me. ...

Loading a Form from VBA
Hi all, I'd like a module to open and load a form in my Access 2003 database... How can I do this? Use the OpenForm method. Look in the Help file for details. -- Doug Steele, Microsoft Access MVP http://I.Am/DougSteele (no e-mails, please!) "Mike" <michael.leon.schwartz@gmail.com> wrote in message news:1184770076.109526.207900@o11g2000prd.googlegroups.com... > Hi all, I'd like a module to open and load a form in my Access 2003 > database... How can I do this? > On Jul 18, 10:58 am, "Douglas J. Steele" <NOSPAM_djsteele@NOSPAM_canada.com&g...

Excel and VBA
I am very interested in learning more about using VBA in office, especially Excel. Can you post some resources (online, books, etc) that can be used to help learn about using Visual Basic in office. Thanks! Here's a good place to start: http://www.contextures.com/xlbooks.html Does that help? *********** Regards, Ron XL2002, WinXP "Bob Sinclair" wrote: > I am very interested in learning more about using VBA in office, especially > Excel. Can you post some resources (online, books, etc) that can be used to > help learn about using Visual Basic in office. >...

minimum cell value
Hi, I am trying to set up a cell so it has a minimum value. The current formula is: =a1/a2*5 which gives the answer 0 but i need to show a minimum value of 1 is this possible? Hi, Doug, Try: =Max(a1/a2*5,1) --- Regards, Norman "Doug Bell" <Doug Bell@discussions.microsoft.com> wrote in message news:8766BC4D-D3CD-4B4F-AF7B-FD145DE56205@microsoft.com... > Hi, > > I am trying to set up a cell so it has a minimum value. > > The current formula is: =a1/a2*5 which gives the answer 0 but i need to > show > a minimum value of 1 is this possible? > ...

Different beginning cell each time for same macro
I would like my macro to begin in a different cell that I select each time and then have the first step of the macro select the 12 cells immediately to the right of the cell I select each time. Currently my macro runs perfectly except that the macro will only begin in the exact same cell every time the marco is run. This means that the same 13 cells are used by the macro every time. Where as I need the marco to begin in a different cell that I more or less randomly select and then the macro should select the 12 cells immediately to the right of that cell. I know someone out there...

VBA Customization
Is there a way to get the name of the current company through VBA in Great Plains 8.0? Thanks for all your help. open GreatPlains. Add the current window, it will add the Toolbar then add fields choose the company name on the top left after the user id. >-----Original Message----- >Is there a way to get the name of the current company through VBA in Great >Plains 8.0? > >Thanks for all your help. > > > >. > Thanks. I tried, but I couldn't add company name to the field list. It opens up the login screen instead. Any thoughts? Thanks again. "ger...

Cells are Merged. How to know where to where???
Hi, i have a merged cells say (a1 to b5). Now i am trying to know, 1) whether the cell is merged or not 2) if merged, where to where, from which cell to which cell Your help will highly be appreciated. Huge Thanks musa.biralo Dim cell As Range Dim coll As Collection Dim collItem Set coll = New Collection For Each cell In Range("A1:B5") On Error Resume Next If cell.MergeCells Then coll.Add cell.MergeArea.Address(False, False), _ cell.MergeArea.Address(False, False) End If On Error GoTo 0 Next cell ...

Count references within a cell
Would anyone be able to help with the following. I'm trying to count entries within a single cell, e.g. Cell A1 may contain the following nnnyynnyynynyny (these are all responses to information and have to be, unfortunately, recorded within the one cell). Therefore what I want to be able to do is then have a separate column that will say: Count every 1st character within range (A1:G1) if not equal to N - and then there will be a second column that will do the same for the 2nd character etc. etc. (altogether, there will be 15 entries which will be counted across column A to G). Is t...

Run VBA without show
I want excel to run the VBA code without showing me what it is doing. Which code should i use for that? Sub RunWithoutShow() Application.ScreenUpdating = False 'Paste the vba code here 'end of code 'Change screenupdating property to true Application.ScreenUpdating = True End Sub I hope this helps... Selva V Pasupathy For more on Excel, VBA, & other Resources Please visit: http://socko.wordpress.com You may also (inserting into quote from code example bellow from Socko) Use Application.Visible property to hide the application entirely Sub RunWithoutShow() Appli...

Form Controls vs VBA controls
I am new to VBA so just finding my feet, can anyone help me with th differences between an excel control (i.e. one from the form toolbox lets say a checkBox and a vba checkBox? From trying the two controls the I have noticed is that you canno capture the change event of the VBA checkbox in the code module, it ha to be done via the sheet (i.e. checkbox on sheet1, code goes in chang event on sheet1) the control is placed on, is this correct? What woul you do if you have three sheets with the same controls just differen data, do you really have to code the control 3 times? The excel control ho...

Referencing a ComboBox in VBA
Hi, I am using Excel 2007. I want to run some code in my Workbook_Open() Sub that fills a combo box on one of my Worksheets (I will call it myCombo on mySheet). I tried the following code and it did not work: myCombo.Clear myCombo.AddItem "Item One" myCombo.AddItem "Item Two" myCombo.AddItem "Item Three" I assume that the problem is that within the Workbook_Open() Sub, the reference to myCombo is not valid. Can anyone tell me if/how I can get a valid reference to myCombo (on mySheet)? Thanks in advance, Paul Kraemer -- Paul Krae...

color-coding cells and more
Excel 97 / W98 Two easy questions. Is there a way to color-code a cell based on a condition, BUT not using Visual Basic Editor? That is, I want to change a cell based on a condition using the =IF(a,b,c) format. In the status bar, I have choices of SUM, Average, and a few others. Always opens with SUM as the default option. Can I change the default to 'Average?' -- Replace the AT in address Statistics convinces us we are in a minority. Probability convinces us we are psychic. Old guy wrote: > Is there a way to color-code a cell based on a condition, BUT not > ...

inserting and renaming a sheet vba
Instead of having 2 lines of code, one to insert a new sheet and one t rename it, is there a way to insert a sheet with particular name i one go -- Matt Housto ----------------------------------------------------------------------- Matt Houston's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=451 View this thread: http://www.excelforum.com/showthread.php?threadid=26717 ...

Cell Selection issue
Morning all. I'm making a user form, and want to select a cell to place my equation, then with that selection choice, offset upwards, and to the side, to select and merge two sets of two cells, each. I understand with my selection that I'd use the following: activecell.offset(0,1).select to get my first cell selection. But how do I retain that initial selection, and then offset one more up, to then merge those two cells? Thank you. I'm not 100% sure what you are wanting but I think you want to merge the cell to the right of the activecell with the cell one r...

VBA??
Is there any way i can input certain numbers and they change to words. for example. 2001 Omagh 2002 Craigavon 2027 Housing Benefit 2036 IT Replacment any help please thanks monty If you mean you want to enter 2001 in cell A1 and have "Omagh" magically appear in its place when you hit the return key, I don't think it can be done. However, if you enter 2001 in cell A1 and have a VLOOKUP formula in cell B1, with reference data stored elsewhere in the sprdsht, that is easily done. Monty How many substitutes do you have? You are probably best to set up a separate table with ...