close

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

Sub Macro1()
ActiveCell.FormulaR1C1 = quot;=TEXT(ROUND(10000*RAND(),0),quot;quot;0000quot;quot;)quot;
Selection.Copy
Selection.PasteSpecial Paste:=xlValues
Application.CutCopyMode = False
End Subquot;Mike Rogersquot; wrote:

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

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 quot;DataInputquot; sheet and paste)

Mike Rogers

quot;Slothquot; wrote:

gt; Sub Macro1()
gt; ActiveCell.FormulaR1C1 = quot;=TEXT(ROUND(10000*RAND(),0),quot;quot;0000quot;quot;)quot;
gt; Selection.Copy
gt; Selection.PasteSpecial Paste:=xlValues
gt; Application.CutCopyMode = False
gt; End Sub
gt;
gt;
gt; quot;Mike Rogersquot; wrote:
gt;
gt; gt; XL2K
gt; gt;
gt; gt; Is it possible to use a macro to place a random number in the active cell,
gt; gt; and not re-calc? I am trying to place a 4 diget ID number in a cell and need
gt; gt; it to not re-calc. I would like it to be random as opposed to assigned. Is
gt; gt; there a better way?
gt; gt;
gt; gt; Mike Rogers

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 = quot;=TEXT(ROUND(10000*RAND(),0),quot;quot;0000quot;quot;)quot;
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 quot;View codequot;. Right click on ThisWorkbook and
goto
Insert-gt;Module. Paste the code there.

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

quot;Mike Rogersquot; wrote:

gt; Sloth
gt;
gt; Thank you for the speedy response!!! One thing that is really important that
gt; I did not mention in my original post. (opps) The active cell to place this
gt; random number is in the range of E17:E50. Would this macro be placed in the
gt; sheet Module? (Select tab, view code, setect quot;DataInputquot; sheet and paste)
gt;
gt; Mike Rogers
gt;
gt; quot;Slothquot; wrote:
gt;
gt; gt; Sub Macro1()
gt; gt; ActiveCell.FormulaR1C1 = quot;=TEXT(ROUND(10000*RAND(),0),quot;quot;0000quot;quot;)quot;
gt; gt; Selection.Copy
gt; gt; Selection.PasteSpecial Paste:=xlValues
gt; gt; Application.CutCopyMode = False
gt; gt; End Sub
gt; gt;
gt; gt;
gt; gt; quot;Mike Rogersquot; wrote:
gt; gt;
gt; gt; gt; XL2K
gt; gt; gt;
gt; gt; gt; Is it possible to use a macro to place a random number in the active cell,
gt; gt; gt; and not re-calc? I am trying to place a 4 diget ID number in a cell and need
gt; gt; gt; it to not re-calc. I would like it to be random as opposed to assigned. Is
gt; gt; gt; there a better way?
gt; gt; gt;
gt; gt; gt; Mike Rogers

Sloth

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

Got it working and thanks again for the help

Mike Rogers

quot;Slothquot; wrote:

gt; for a range of cells use this. Select the range you want to insert the
gt; numbers in and run the macro.
gt;
gt; Sub Macro1()
gt; Dim myCell As Range
gt; For Each myCell In Selection.Cells
gt; myCell.FormulaR1C1 = quot;=TEXT(ROUND(10000*RAND(),0),quot;quot;0000quot;quot;)quot;
gt; Next myCell
gt; Selection.Copy
gt; Selection.PasteSpecial Paste:=xlValues
gt; Application.CutCopyMode = False
gt; End Sub
gt;
gt; To your other question about where to place it. It goes in a module. Right
gt; click the sheet tab and select quot;View codequot;. Right click on ThisWorkbook and
gt; goto
gt; Insert-gt;Module. Paste the code there.
gt;
gt; Forgive me, but I don't know what quot;DataInputquot; is. My knowledge of Macros
gt; and VBA is extremely limited.
gt;
gt; quot;Mike Rogersquot; wrote:
gt;
gt; gt; Sloth
gt; gt;
gt; gt; Thank you for the speedy response!!! One thing that is really important that
gt; gt; I did not mention in my original post. (opps) The active cell to place this
gt; gt; random number is in the range of E17:E50. Would this macro be placed in the
gt; gt; sheet Module? (Select tab, view code, setect quot;DataInputquot; sheet and paste)
gt; gt;
gt; gt; Mike Rogers
gt; gt;
gt; gt; quot;Slothquot; wrote:
gt; gt;
gt; gt; gt; Sub Macro1()
gt; gt; gt; ActiveCell.FormulaR1C1 = quot;=TEXT(ROUND(10000*RAND(),0),quot;quot;0000quot;quot;)quot;
gt; gt; gt; Selection.Copy
gt; gt; gt; Selection.PasteSpecial Paste:=xlValues
gt; gt; gt; Application.CutCopyMode = False
gt; gt; gt; End Sub
gt; gt; gt;
gt; gt; gt;
gt; gt; gt; quot;Mike Rogersquot; wrote:
gt; gt; gt;
gt; gt; gt; gt; XL2K
gt; gt; gt; gt;
gt; gt; gt; gt; Is it possible to use a macro to place a random number in the active cell,
gt; gt; gt; gt; and not re-calc? I am trying to place a 4 diget ID number in a cell and need
gt; gt; gt; gt; it to not re-calc. I would like it to be random as opposed to assigned. Is
gt; gt; gt; gt; there a better way?
gt; gt; gt; gt;
gt; gt; gt; gt; Mike Rogers

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 software 的頭像
    software

    software

    software 發表在 痞客邦 留言(0) 人氣()