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

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
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,216,052
Messages
6,128,509
Members
449,455
Latest member
jesski

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