I have tried to run this sub for generating a random sample, but when I try to fix the formula I get only an error message in the cells " Name", in state of gettings the values. Can someone help?
This is the code, thanks:
Option Explicit
Sub Simulation()
Dim iSize As Integer, pMean As Double, pSD As Double, iBins As String
iBins = 15
iSize = InputBox("New sheet: The size of your sample:", , 100)
pMean = InputBox("New sheet: The mean of yoursample:", , 10)
pSD = InputBox("New sheet: The SD of your sample:", , 0.2)
Set oWS = Worksheets.Add(, ActiveSheet)
Range(Cells(1, 1), Cells(iSize, 1)).Formula = "=Application.WorksheetFunction.NormInv(Rnd(), " & pMean & " , " & pSD & ")"
Range(Cells(1, 1), Cells(iSize, 1)).Formula = Range(Cells(1, 1), Cells(iSize, 1)).Value
Range("E1") = Application.WorksheetFunction.Average(Columns(1))
end sub
Range.Formula
needs a formula like you would input in Excel cells, take out the.Formula
from your ranges and it will work allright. – Damian Sep 18 '19 at 15:23Range
,Cells
, andColumns
calls should be done againstoWS
. – Mathieu Guindon Sep 18 '19 at 15:50