#1   Report Post  
Posted to microsoft.public.excel.misc
Mike Rogers
 
Posts: n/a
Default Random number Macro

XL2K

Is it possible to use a macro to place a random number in the active cell,
and not re-calc? I am trying to place a 4 diget ID number in a cell and need
it to not re-calc. I would like it to be random as opposed to assigned. Is
there a better way?

Mike Rogers
  #2   Report Post  
Posted to microsoft.public.excel.misc
Sloth
 
Posts: n/a
Default Random number Macro

Sub Macro1()
ActiveCell.FormulaR1C1 = "=TEXT(ROUND(10000*RAND(),0),""0000"")"
Selection.Copy
Selection.PasteSpecial Paste:=xlValues
Application.CutCopyMode = False
End Sub


"Mike Rogers" wrote:

XL2K

Is it possible to use a macro to place a random number in the active cell,
and not re-calc? I am trying to place a 4 diget ID number in a cell and need
it to not re-calc. I would like it to be random as opposed to assigned. Is
there a better way?

Mike Rogers

  #3   Report Post  
Posted to microsoft.public.excel.misc
Mike Rogers
 
Posts: n/a
Default Random number Macro

Sloth

Thank you for the speedy response!!! One thing that is really important that
I did not mention in my original post. (opps) The active cell to place this
random number is in the range of E17:E50. Would this macro be placed in the
sheet Module? (Select tab, view code, setect "DataInput" sheet and paste)

Mike Rogers

"Sloth" wrote:

Sub Macro1()
ActiveCell.FormulaR1C1 = "=TEXT(ROUND(10000*RAND(),0),""0000"")"
Selection.Copy
Selection.PasteSpecial Paste:=xlValues
Application.CutCopyMode = False
End Sub


"Mike Rogers" wrote:

XL2K

Is it possible to use a macro to place a random number in the active cell,
and not re-calc? I am trying to place a 4 diget ID number in a cell and need
it to not re-calc. I would like it to be random as opposed to assigned. Is
there a better way?

Mike Rogers

  #4   Report Post  
Posted to microsoft.public.excel.misc
Sloth
 
Posts: n/a
Default Random number Macro

for a range of cells use this. Select the range you want to insert the
numbers in and run the macro.

Sub Macro1()
Dim myCell As Range
For Each myCell In Selection.Cells
myCell.FormulaR1C1 = "=TEXT(ROUND(10000*RAND(),0),""0000"")"
Next myCell
Selection.Copy
Selection.PasteSpecial Paste:=xlValues
Application.CutCopyMode = False
End Sub

To your other question about where to place it. It goes in a module. Right
click the sheet tab and select "View code". Right click on ThisWorkbook and
goto
Insert-Module. Paste the code there.

Forgive me, but I don't know what "DataInput" is. My knowledge of Macros
and VBA is extremely limited.

"Mike Rogers" wrote:

Sloth

Thank you for the speedy response!!! One thing that is really important that
I did not mention in my original post. (opps) The active cell to place this
random number is in the range of E17:E50. Would this macro be placed in the
sheet Module? (Select tab, view code, setect "DataInput" sheet and paste)

Mike Rogers

"Sloth" wrote:

Sub Macro1()
ActiveCell.FormulaR1C1 = "=TEXT(ROUND(10000*RAND(),0),""0000"")"
Selection.Copy
Selection.PasteSpecial Paste:=xlValues
Application.CutCopyMode = False
End Sub


"Mike Rogers" wrote:

XL2K

Is it possible to use a macro to place a random number in the active cell,
and not re-calc? I am trying to place a 4 diget ID number in a cell and need
it to not re-calc. I would like it to be random as opposed to assigned. Is
there a better way?

Mike Rogers

  #5   Report Post  
Posted to microsoft.public.excel.misc
Mike Rogers
 
Posts: n/a
Default Random number Macro

Sloth

Thanks for the code... works like you knew it would...
Ohhh yea "DataInput" is the name of my worksheet I thought the code might go
in.

Got it working and thanks again for the help

Mike Rogers

"Sloth" wrote:

for a range of cells use this. Select the range you want to insert the
numbers in and run the macro.

Sub Macro1()
Dim myCell As Range
For Each myCell In Selection.Cells
myCell.FormulaR1C1 = "=TEXT(ROUND(10000*RAND(),0),""0000"")"
Next myCell
Selection.Copy
Selection.PasteSpecial Paste:=xlValues
Application.CutCopyMode = False
End Sub

To your other question about where to place it. It goes in a module. Right
click the sheet tab and select "View code". Right click on ThisWorkbook and
goto
Insert-Module. Paste the code there.

Forgive me, but I don't know what "DataInput" is. My knowledge of Macros
and VBA is extremely limited.

"Mike Rogers" wrote:

Sloth

Thank you for the speedy response!!! One thing that is really important that
I did not mention in my original post. (opps) The active cell to place this
random number is in the range of E17:E50. Would this macro be placed in the
sheet Module? (Select tab, view code, setect "DataInput" sheet and paste)

Mike Rogers

"Sloth" wrote:

Sub Macro1()
ActiveCell.FormulaR1C1 = "=TEXT(ROUND(10000*RAND(),0),""0000"")"
Selection.Copy
Selection.PasteSpecial Paste:=xlValues
Application.CutCopyMode = False
End Sub


"Mike Rogers" wrote:

XL2K

Is it possible to use a macro to place a random number in the active cell,
and not re-calc? I am trying to place a 4 diget ID number in a cell and need
it to not re-calc. I would like it to be random as opposed to assigned. Is
there a better way?

Mike Rogers

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
Random Number generator Neil M Excel Worksheet Functions 2 February 1st 06 06:00 PM
Random letter and number generator Marie1uk Excel Worksheet Functions 4 January 23rd 06 06:04 PM
random number with text T Harris Excel Worksheet Functions 10 December 30th 05 04:34 PM
Closing File Error jcliquidtension Excel Discussion (Misc queries) 4 October 20th 05 12:22 PM
Macro, select Sheet "Number", NOT Sheet Name DAA Excel Worksheet Functions 4 November 30th 04 05:29 PM


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

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

About Us

"It's about Microsoft Excel"