VBA - Keep getting Type: Mismatch on my code

NessPJ

Active Member
Joined
May 10, 2011
Messages
422
Office Version
  1. 365
Hello all,

I keep getting a Type: Mismatch error on the following code (orange line):
Rich (BB code):
    Dim Tijdwaarde As Variant

    Tijdwaarde = Sheets("Par").Range("B30").Value

    LastRowATImpSht = Range("C" & "65536").End(xlUp).Row
    
    For i = 2 To LastRowATImpSht Step 1
        Range("F" & i).Value = Format(Range("F" & i).Value, "HH:MM") - TimeSerial(0, Tijdwaarde, 0)
    Next i

I also tried putting Tijdwaarde As String, since i use a "TimeSerial" function but that did not seem to solve the issue.

Any ideas what i'm doing wrong here? :)
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Format returns a string and TimeSerial returns a number, you can't subtract a number from a string.

What are you trying to do?

Are you trying to subtract hours from a date/time?
 
Upvote 0
Are you trying to do this?

Code:
Range("F" & i).Value = Format(Range("F" & i).Value - TimeSerial(0, Tijdwaarde, 0), "HH:MM")

WBD
 
Upvote 0
@ Norie:
Yes, i'm trying to deduct 30 minutes from a timevalue.
I did not know the Format function always returned as a String, thanks for the info.

@ WBD:
That does exactly what i'm looking for, thanks!
 
Upvote 0

Forum statistics

Threads
1,223,901
Messages
6,175,277
Members
452,629
Latest member
SahilPolekar

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