Type Mismatch Error When calling Sub

Joined
Oct 15, 2018
Messages
5
Hi


I have a procedure that runs fine when I run it standalone but when I call it from another sub it generates a Type Mismatch Error (run time error 13)




For i = 4 To ColNum
Cells(8, i).Value = Cells(4, i) / Cells(5, i)
'calculate standardized
Sheets("Probit").Cells(11, i).Value = Cells(4, i) * Application.StDev(Range(Cells(15, i), (Cells(LastRow, i)))) / WorksheetFunction.StDev(Range(Cells(15, 2), (Cells(LastRow, 2))))


The first line "(Cells(8, i).Value = Cells(4, i) / Cells(5, i)) "populates fine but the next section with the standard deviation calculation generates the error. i.e debugging takes me to this line:


Sheets("Probit").Cells(11, i).Value = Cells(4, i) * Application.StDev(Range(Cells(15, i), (Cells(LastRow, i)))) / WorksheetFunction.StDev(Range(Cells(15, 2), (Cells(LastRow, 2))))



I've tried different things but cannot get it to run without an error when calling the sub that this bit of code sits in. Any ideas for fixes?

This is how the variables are defined
Dim LastRow As Long, i As Long
Dim ColNum As Integer, obs As Integer, outvariables As Integer



Thanks

AEM
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Are all those cells on that line on the same sheet?
 
Upvote 0
Hi

Yes all of the code relates to the same sheet. The error occurs at this line only: The proceeding line runs/calculates fine:

Sheets("Probit").Cells(11, i).Value = Cells(4, i) * Application.StDev(Range(Cells(15, i), (Cells(LastRow, i)))) / Application.StDev(Range(Cells(15, 2), (Cells(LastRow, 2))))
 
Upvote 0
I suspect that the "Probit" is not the active sheet & you also seem to have some extra brackets, try
Code:
With Sheets("Probit")
   .Cells(11, i).Value = .Cells(4, i) * Application.StDev(.Range(.Cells(15, i), .Cells(LastRow, i))) / Application.StDev(.Range(.Cells(15, 2), .Cells(LastRow, 2)))
End With
 
Upvote 0
Thanks Fluf.

I tried your code but still get the same error and can confirm the sheet name is correct.

As I mentioned, when I run the sub by itself instead of calling it from another procedure it calculates fine without any errors so the formula/sheet references etc does not appear to be the issue.

Also right before this sub is called there is another sub that gets called. To test I removed the other sub call - and now the call to this sub now works fine without error. So it looks like there is some conflict between the two subs that get called in the procedure. I have no idea why. They both reference the same sheet but do slightly different things!

AEM
 
Upvote 0
Check that none of the cells that line is looking at when you get the error contain formulaic errors such as #N/A #VALUE etc
 
Upvote 0

Forum statistics

Threads
1,223,888
Messages
6,175,206
Members
452,618
Latest member
Tam84

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