can anyone help me to see what is wrong with my code

jovie

Board Regular
Joined
Nov 13, 2015
Messages
68
It said error 13 type mismatch

Rich (BB code):
Sub Most_frequently_used_tools()
Dim strData As String
Dim item As String
Dim diameter As String
Dim rng As Range
Dim maximum As Variant
Dim rngCol As Range
Dim lngRow As Long
Dim rngAdd As Range
     
'Enter desired range in which to find the maximum value
strData = "Total_tools_out"

Set rng = Range(strData)
     
'Determines maximum value in range
maximum = Application.WorksheetFunction.Max(rng)
 
For Each rngCol In rng.Columns

'Returns row number of the maximum value, in the column which has the same
lngRow = Application.WorksheetFunction.Match(maximum, rngCol, 0)
  
'Returns cell address of the maximum value
Set rngAdd = rngCol.Cells(lngRow, 1)
    
'Selects smallest value to highlight with color
rngAdd.Select

With Selection
tools = Range("item").Value
End With

With Selection
diameter = Range("diameter").Value and point here   
End With
    
With Selection
.Interior.Color = RGB(255, 140, 0)
End With
        
'Message displays the searched range, smallest value, and its address
MsgBox "Most frequently used tools is (""" & tools & """) and size is (""" & diameter & """) total used " & maximum & " number of tools."
Next

With Selection
.Interior.ColorIndex = 0
End With

End Sub
 
Last edited by a moderator:

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
You have diameter declared as a String. If it is a number then it would give you that error. If your value can be a decimal value then diameter probralby should be declared as a Double. Or you could play it safe and declare it as a Variant and let VBA figure it out. Be sure your declarations (Dim statements) reflect how the variables are actually used to avoid the Type Mismatch messages.
 
Upvote 0
Actually my diameter is combine with the diameter symbol, numbers and alphabet, and I am not sure which type is it, so I just put string.
 
Upvote 0
Er....... I just change the type of diameter to variant, and it show
MsgBox "Most frequently used tools is (""" & tools & """) and size is (""" & diameter & """) total used " & maximum & " number of tools."
This one is error 13 type mis match...
Can help me?
 
Upvote 0
In Break mode you can hover over each variable to see which one is having an issue. That should at least point you in the right direction.
 
Upvote 0
I check my variable, but it seems like no problem, just the
MsgBox "Most frequently used tools is (""" & tools & """) and size is (""" & diameter & """) total used " & maximum & " number of tools."
this one got problem, and I dun know y
 
Upvote 0
I check my variable, but it seems like no problem, just the
this one got problem, and I dun know y

Hi, I don't think you can use quotes in your code like this, """, change it to apostrophe like "'" or "'" & "'"
 
Upvote 0
What exactly is in your range called diameter? I suspect either that refers to more than one cell, or it contains an error.
 
Upvote 0
Neither of those could cause the errors you describe.
 
Upvote 0

Forum statistics

Threads
1,214,943
Messages
6,122,369
Members
449,080
Latest member
Armadillos

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