Error Type mismatch

mks

Board Regular
Joined
Aug 28, 2009
Messages
173
Hi,

I am getting Mismatch error in following code - suggestion please -

Private Sub CommandButton1_Click()
Dim sInp1 As String
Dim sInp2 As String
Dim sInp3 As String
Dim sInp4 As String

Dim sOut As String


sInp1 = InputBox("Enter Length Along Main Ridge")
sInp2 = InputBox("Enter Second Length")
sInp3 = InputBox("Enter Length of Main Hip")
sInp4 = InputBox("Enter Length of Second Hip")



If Len(sInp1) Then
If Len(sInp2) Then
If Len(sInp3) Then
If Len(sInp4) Then

sOut = InputBox("Select Output Cell")

If Len(sOut) Then


Range(sOut).Value = (((sInp1 - (sInp2 / 2)) - ((sInp3 / 2) + ((sInp3 + sInp4) / 4))))



End If
End If
End If
End If
End If

End Sub

thanks
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
If the error is at this line:
Code:
Range(sOut).Value = (((sInp1 - (sInp2 / 2)) - ((sInp3 / 2) + ((sInp3 + sInp4) / 4))))
it's b/c the sInp variables are dim'd as strings and you can't manipulate them like numbers. Also Len(sInp1), ... need to be set = to some value(s) in your If Then statements.
 
Upvote 0
Thanks for reply,

can you please, write the correct code.

The error is coming as you suggested.

Thanks
 
Upvote 0
Thanks for reply,

can you please, write the correct code.

The error is coming as you suggested.

Thanks
Can you tell me what you want to achieve with the code? It's not clear what the If Len(sInp) statements are supposed to do. Are you using those just to ensure the user's returns are valid numbers?
 
Upvote 0
Hi joe,

I want to enter four values and want the return value as per the formula. Once I got the value based on formula than I want to put that Value is nominated cell (SOut). say B1 or C6 - like this.

thanks
 
Upvote 0
Try this (untested):
Code:
Private Sub CommandButton1_Click()
Dim sInp1 As Double
Dim sInp2 As Double
Dim sInp3 As Double
Dim sInp4 As Double
Dim sOut As Range

On Error Resume Next
sInp1 = Application.InputBox("Enter Length Along Main Ridge")
If Not IsNumeric(sInp1) Then Exit Sub
sInp2 = Application.InputBox("Enter Second Length")
If Not IsNumeric(sInp2) Then Exit Sub
sInp3 = Application.InputBox("Enter Length of Main Hip")
If Not IsNumeric(sInp3) Then Exit Sub
sInp4 = Application.InputBox("Enter Length of Second Hip")
If Not IsNumeric(sInp4) Then Exit Sub
Set sOut = Application.InputBox("Select Output Cell", Type:=8)
If sOut Is Nothing Then Exit Sub
sOut.Value = (((sInp1 - (sInp2 / 2)) - ((sInp3 / 2) + ((sInp3 + sInp4) / 4))))

End Sub
 
Upvote 0

Forum statistics

Threads
1,224,597
Messages
6,179,813
Members
452,945
Latest member
Bib195

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