Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 275
Default Chnge code help requited

Hi,
I have been given this code to randomly chose a number from range R36:R57
then copy it to cell E34

Sub getnumber()
x = Int((52 - 32 + 1) * Rnd + 32)
mynumber = Worksheets("sheet1").Cells(x, 18).Value
Worksheets("sheet1").Cells(14, 4).Value = mynumber
End Sub

2 changes to the code are required please
1) when a number is selected from the range and pasted to E14 can it be
removed from the original range?
2) If a blank cell is randomly selected, ignore it and loop until a number
is found.

Hope this can be done and thanks in advance
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Chnge code help requited

Sub getnumber()
mynumber = ""
Do While mynumber = ""
x = Int((57 - 32 + 1) * Rnd + 32)
mynumber = Worksheets("sheet1").Cells(x, 18).Value
Worksheets("sheet1").Cells(x, 18).Clear
Worksheets("sheet1").Cells(34, 5).Value = mynumber
Loop
End Sub


will pick a value randmly from R36:R57 then copy it to cell E34
then do the clear and then loop if necessary

--
Gary''s Student
gsnu200710


"Anthony" wrote:

Hi,
I have been given this code to randomly chose a number from range R36:R57
then copy it to cell E34

Sub getnumber()
x = Int((52 - 32 + 1) * Rnd + 32)
mynumber = Worksheets("sheet1").Cells(x, 18).Value
Worksheets("sheet1").Cells(14, 4).Value = mynumber
End Sub

2 changes to the code are required please
1) when a number is selected from the range and pasted to E14 can it be
removed from the original range?
2) If a blank cell is randomly selected, ignore it and loop until a number
is found.

Hope this can be done and thanks in advance

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 275
Default Chnge code help requited

thanks for that - just great

"Gary''s Student" wrote:

Sub getnumber()
mynumber = ""
Do While mynumber = ""
x = Int((57 - 32 + 1) * Rnd + 32)
mynumber = Worksheets("sheet1").Cells(x, 18).Value
Worksheets("sheet1").Cells(x, 18).Clear
Worksheets("sheet1").Cells(34, 5).Value = mynumber
Loop
End Sub


will pick a value randmly from R36:R57 then copy it to cell E34
then do the clear and then loop if necessary

--
Gary''s Student
gsnu200710


"Anthony" wrote:

Hi,
I have been given this code to randomly chose a number from range R36:R57
then copy it to cell E34

Sub getnumber()
x = Int((52 - 32 + 1) * Rnd + 32)
mynumber = Worksheets("sheet1").Cells(x, 18).Value
Worksheets("sheet1").Cells(14, 4).Value = mynumber
End Sub

2 changes to the code are required please
1) when a number is selected from the range and pasted to E14 can it be
removed from the original range?
2) If a blank cell is randomly selected, ignore it and loop until a number
is found.

Hope this can be done and thanks in advance

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Chnge view order, Area chrt? Boswell Charts and Charting in Excel 1 October 14th 07 02:09 AM
Shorten code to apply to all sheets except a few, instead of individually naming them, and later adding to code. Corey Excel Programming 3 December 11th 06 05:14 AM
Protect Sheet with code, but then code will not Paste error. How do i get around this. Please read for explainations.... Corey Excel Programming 4 November 25th 06 04:57 AM
Excel code convert to Access code - Concat & eliminate duplicates italia Excel Programming 1 September 12th 06 12:14 AM
How to chnge 35 relative cells to 35 absolute cells at one time. Susan A at Millennium Medical Excel Worksheet Functions 3 March 7th 06 08:12 PM


All times are GMT +1. The time now is 03:49 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"