Type Mismatch error question

julhs

Active Member
Joined
Dec 3, 2018
Messages
471
Office Version
  1. 2010
Platform
  1. Windows
I need help to resolve the “Type Mismatch” error.
Posting this is a bit of a cop out!! But having spent last few hours trying to solve it myself, I turn to my trusted source for help!!
Code is this:-
VBA Code:
Sub MeUsedRangetest()
Dim lastRow As Long, firstrow As Long
Dim rng As Range
Dim sht As Worksheet
       Set sht = ThisWorkbook.ActiveSheet
       Set rng = sht.Range("T:T").Find(what:="CF rules", LookIn:=xlValues, LookAt:=xlWhole).Row
       Set rng = sht.Range("T:T").Find(what:="Cash Paid", LookIn:=xlValues, LookAt:=xlWhole).Row

          firstrow = sht.Range("T:T").Find(what:="CF rules", LookIn:=xlValues, LookAt:=xlWhole).Row
          lastRow = sht.Range("T:T").Find(what:="Cash Paid", LookIn:=xlValues, LookAt:=xlWhole).Row

      MsgBox "Range is " & rng.Address

End Sub

Getting Compile error = Type Mismatch, on this line:
VBA Code:
Set rng = sht.Range("T:T").Find(what:="CF rules", LookIn:=xlValues, LookAt:=xlWhole).Row
 
Sorry vtito to be sounding “particular” but your first post#2 was exactly the SAME code that I posted.
But you left out any mention of deleting the 2 “Set rng lines
This is what I BELIEVE your suggested code should be:-
Excel Formula:
Sub MeUsedRangetest()
Dim lastRow As Long, firstrow As Long
Dim rng As Range
Dim sht As Worksheet
    Set sht = ThisWorkbook.ActiveSheet
       firstrow = sht.Range("T:T").Find(what:="CF rules", LookIn:=xlValues, LookAt:=xlWhole).Row
       lastRow = sht.Range("T:T").Find(what:="Cash Paid", LookIn:=xlValues, LookAt:=xlWhole).Row
   Set rng = sht.Range("T" & firstrow & ":T" & lastRow)
         MsgBox "Range is " & rng.Address
End Sub
But it is bugging out on:-
firstrow = sht.Range("T:T").Find(what:="CF rules", LookIn:=xlValues, LookAt:=xlWhole).Row
With the Error message:-
Run Time Error 91, Object Variable or with Block variable not set
 
Upvote 0

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
The code in post#2 is NOT the same as the code you posted.

The error 91 means that "CF rules" was not found in col T of the activesheet.
 
Upvote 0
My SINCERE apologies vtito.!!
The ONLY thing I can think is that I ended up pasting MY OWN code back into the module and NOT yours;
hence my remark that they were “EXACTLY the SAME”
Also to make matters worse; I have been trailing /testing so much stuff on a couple of different sheets that I completely missed that I had moved "CF rules" from Col T to Col S so code was NEVER going to find “CF rules” in Col T on the sheet I ran the code BECAUSE they were actually in Col S, hence the further errors.

Thank you for your help and sorry for MY MESS UPS!!
 
Upvote 0
Fluff.
Your comments where what made me look again at stuff and realise MY MESS UPS.
 
Upvote 0

Forum statistics

Threads
1,223,896
Messages
6,175,260
Members
452,627
Latest member
KitkatToby

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