Worksheet Function across Range (VBA)

expeo

New Member
Joined
Dec 1, 2017
Messages
17
I am not sure what I am doing wrong here. It errors out when it reaches the worksheetfunction

Code:
Sub STwoFill()


Dim rng As Range: Set rng = Application.Range("STwo!C14:C1013")
Dim cel As Range


Dim NorMean As Integer
Dim NorSD As Integer


NorMean = Sheets("STwo").Range("C5").Value
NorSD = Sheets("STwo").Range("C6").Value

Randomize 'Not sure if this part is needed, but I have tried using with and without. 


For Each cel In rng.Cells
    With cel
        .Value = Round(WorksheetFunction.Norm_Inv(Rnd(), NorMean, NorSD))
    End With
Next cel
  
End Sub
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Hello expeo,

The Norm_Inv arguments all need to be Double, not Integer. Numbers in cells on the worksheet are always Double data typed.
Code:
Sub STwoFill()


Dim rng As Range: Set rng = Application.Range("STwo!C14:C1013")
Dim cel As Range




Dim NorMean As Double
Dim NorSD As Double




NorMean = Sheets("STwo").Range("C5").Value
NorSD = Sheets("STwo").Range("C6").Value


Randomize 'Not sure if this part is needed, but I have tried using with and without.




For Each cel In rng.Cells
    With cel
        .Value = Round(WorksheetFunction.Norm_Inv(Rnd(), NorMean, NorSD))
    End With
Next cel
  
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top