Tulyderrin
New Member
- Joined
- Dec 11, 2018
- Messages
- 3
Hi All, - 1st post.
I've lurked around here for a while - some really useful hints & tips !
I have a range of postcodes in a column. (The sheet is FARMDATA the Column is G:G) There are 1000's of cells each with a unique code.
I've written an amateurish vba function to generate a single random selection of those postcodes :
[/vba]
Function RandCell(Rg As Range) As Range
Set RandCell = Application.WorksheetFunction.index(Rg, Application.WorksheetFunction.RandBetween(1, Application.WorksheetFunction.CountA(Rg)), 1)
End Function
[/vba]
When I use this function in a cell =RandCell(FARMDATA!G:G) it successfully selects a random postcode from the list in FARMDATA column D and returns it to the cell.
But - everytime I change another cell on that sheet, my random selection also changes.
I know this is because "RandBetween" is Volatile.
Is there some code that I can add to my RandCell function that gets around this ?
I've been trying to use xlpastespecial.values - I read somewhere that just pasting values makes them static but I cannot figure that out..........
like I say - amateur !
thanks a lot everyone ...... any pointers gratefully accepted.
Tulyderrin
I've lurked around here for a while - some really useful hints & tips !
I have a range of postcodes in a column. (The sheet is FARMDATA the Column is G:G) There are 1000's of cells each with a unique code.
I've written an amateurish vba function to generate a single random selection of those postcodes :
[/vba]
Function RandCell(Rg As Range) As Range
Set RandCell = Application.WorksheetFunction.index(Rg, Application.WorksheetFunction.RandBetween(1, Application.WorksheetFunction.CountA(Rg)), 1)
End Function
[/vba]
When I use this function in a cell =RandCell(FARMDATA!G:G) it successfully selects a random postcode from the list in FARMDATA column D and returns it to the cell.
But - everytime I change another cell on that sheet, my random selection also changes.
I know this is because "RandBetween" is Volatile.
Is there some code that I can add to my RandCell function that gets around this ?
I've been trying to use xlpastespecial.values - I read somewhere that just pasting values makes them static but I cannot figure that out..........
like I say - amateur !
thanks a lot everyone ...... any pointers gratefully accepted.
Tulyderrin