Type mismatch error

skull_eagle

Board Regular
Joined
Mar 25, 2011
Messages
89
Hi Everyone,
I need to run some code with a large amount of variables.

When running the below code, it runs "Line 1" and "Line 2" code no problem as soon as it hits the "Line 3" code it gives me a Type mismatch error on every line of code that contains a 'Time(?,?,?)' statement.

If it has already run these statements in "Line 1" and "Line 2" code I can't see why it would be having issues in the "Line 3" area.

Any help would be greatly appreciated.

(I apologise for the large amount of code)


[face=Courier New]
Code:
[color=darkblue]Do[/color]
    [color=darkblue]If[/color] ActiveCell.Offset(0, -15) = "On-site" [color=darkblue]Then[/color] [color=darkblue]GoTo[/color] Line1 [color=darkblue]Else[/color]
    [color=darkblue]If[/color] ActiveCell.Offset(0, -15) = "Creation" [color=darkblue]Then[/color] [color=darkblue]GoTo[/color] Line2 [color=darkblue]Else[/color]
    [color=darkblue]If[/color] ActiveCell.Offset(0, -15) = "Off-site" [color=darkblue]Then[/color] [color=darkblue]GoTo[/color] Line3
    
    
Line1:
                [color=darkblue]If[/color] ActiveCell.Offset(0, -13) = "Sat/Sun" [color=darkblue]Then[/color]
                                                ActiveCell.FormulaR1C1 = "=RC[-2]-TIME(8,0,0)"
                [color=darkblue]If[/color] ActiveCell.Offset(0, -1) = 0 [color=darkblue]Then[/color]
                                [color=darkblue]If[/color] ActiveCell.Offset(0, -12) >= Time(8, 0, 0) [color=darkblue]Then[/color]
                                                ActiveCell.FormulaR1C1 = "=RC[-2]-RC[-12]"
                                [color=darkblue]If[/color] ActiveCell.Offset(0, -12) < Time(8, 0, 0) [color=darkblue]Then[/color]
                                                ActiveCell.FormulaR1C1 = "=(RC[-2]-RC[-12])+(TIME(8,0,0)-RC[-12])"
                [color=darkblue]If[/color] ActiveCell.Offset(0, -1) >= 1 [color=darkblue]Then[/color]
                                [color=darkblue]If[/color] ActiveCell.Offset(0, -12) > Time(18, 0, 0) [color=darkblue]Then[/color]
                                                ActiveCell.FormulaR1C1 = "=RC[-2]-TIME(8,0,0)"
                                [color=darkblue]If[/color] ActiveCell.Offset(0, -12) <= Time(18, 0, 0) [color=darkblue]Then[/color]
                                                ActiveCell.FormulaR1C1 = "=(TIME(18,0,0)-RC[-12])+(RC[-2]-TIME(8,0,0))"
[color=darkblue]GoTo[/color] Line4
 
                [color=darkblue]End[/color] [color=darkblue]If[/color]
                [color=darkblue]End[/color] [color=darkblue]If[/color]
                                [color=darkblue]End[/color] [color=darkblue]If[/color]
                                [color=darkblue]End[/color] [color=darkblue]If[/color]
                [color=darkblue]End[/color] [color=darkblue]If[/color]
                                [color=darkblue]End[/color] [color=darkblue]If[/color]
                                [color=darkblue]End[/color] [color=darkblue]If[/color]
                                             
Line2:
                [color=darkblue]If[/color] ActiveCell.Offset(0, -13) = "Sat/Sun" [color=darkblue]Then[/color]
                                                ActiveCell.FormulaR1C1 = "=RC[-2]-TIME(8,0,0)"
                [color=darkblue]If[/color] ActiveCell.Offset(0, -1) = 0 [color=darkblue]Then[/color]
                                [color=darkblue]If[/color] ActiveCell.Offset(0, -12) >= Time(8, 0, 0) [color=darkblue]Then[/color]
                                                ActiveCell.FormulaR1C1 = "=RC[-2]-RC[-12]"
                                [color=darkblue]If[/color] ActiveCell.Offset(0, -12) < Time(8, 0, 0) [color=darkblue]Then[/color]
                                                ActiveCell.FormulaR1C1 = "=(RC[-2]-RC[-12])+(TIME(8,0,0)-RC[-12])"
                [color=darkblue]If[/color] ActiveCell.Offset(0, -1) >= 1 [color=darkblue]Then[/color]
                                [color=darkblue]If[/color] ActiveCell.Offset(0, -12) > Time(18, 0, 0) [color=darkblue]Then[/color]
                                                ActiveCell.FormulaR1C1 = "=RC[-2]-TIME(8,0,0)"
                                [color=darkblue]If[/color] ActiveCell.Offset(0, -12) <= Time(18, 0, 0) [color=darkblue]Then[/color]
                                                ActiveCell.FormulaR1C1 = "=(TIME(18,0,0)-RC[-12])+(RC[-2]-TIME(8,0,0))"
                                                 
[color=darkblue]GoTo[/color] Line4
  
                [color=darkblue]End[/color] [color=darkblue]If[/color]
                [color=darkblue]End[/color] [color=darkblue]If[/color]
                                [color=darkblue]End[/color] [color=darkblue]If[/color]
                                [color=darkblue]End[/color] [color=darkblue]If[/color]
                [color=darkblue]End[/color] [color=darkblue]If[/color]
                                [color=darkblue]End[/color] [color=darkblue]If[/color]
                                [color=darkblue]End[/color] [color=darkblue]If[/color]
    
Line3:
                [color=darkblue]If[/color] ActiveCell.Offset(0, -14) = "Standard" [color=darkblue]Then[/color]
                                [color=darkblue]If[/color] ActiveCell.Offset(0, -12) >= Time(10, 30, 0) [color=darkblue]Then[/color]
                                                [color=darkblue]If[/color] ActiveCell.Offset(0, -12) <= Time(16, 0, 0) [color=darkblue]Then[/color]
                                                                ActiveCell = Time(0, 15, 0)
                                                [color=darkblue]If[/color] ActiveCell.Offset(0, -12) > Time(16, 0, 0) [color=darkblue]Then[/color]
                                                                ActiveCell.FormulaR1C1 = "=(TIME(0,30,0))+((RC[-2])-TIME(16,0,0))"
                                                                
                                [color=darkblue]If[/color] ActiveCell.Offset(0, -12) < Time(10, 30, 0) [color=darkblue]Then[/color]
                                                [color=darkblue]If[/color] ActiveCell.Offset(0, -2) <= Time(10, 30, 0) [color=darkblue]Then[/color]
                                                                ActiveCell = Time(0, 15, 0)
                                                [color=darkblue]If[/color] ActiveCell.Offset(0, -2) > Time(10, 30, 0) [color=darkblue]Then[/color]
                                                                ActiveCell.FormulaR1C1 = "=(TIME(0,30,0))+((RC[-2])-TIME(16,0,0))"
                                                                
                                [color=darkblue]If[/color] ActiveCell.Offset(0, -12) > Time(16, 0, 0) [color=darkblue]Then[/color]
                                                [color=darkblue]If[/color] ActiveCell.Offset(0, -2) <= Time(10, 30, 0) [color=darkblue]Then[/color]
                                                                ActiveCell = Time(0, 15, 0)
                                                [color=darkblue]If[/color] ActiveCell.Offset(0, -2) > Time(10, 30, 0) [color=darkblue]Then[/color]
                                                                ActiveCell.FormulaR1C1 = "=(TIME(0,30,0))+((RC[-2])-TIME(10,30,0))"
                
                [color=darkblue]If[/color] ActiveCell.Offset(0, -14) = "Urgent" [color=darkblue]Then[/color]
                                [color=darkblue]If[/color] ActiveCell.Offset(0, -13) = "Sat/Sun" [color=darkblue]Then[/color]
                                                ActiveCell.FormulaR1C1 = "=RC[-2]-TIME(8,0,0)"
                                                  
                                [color=darkblue]If[/color] ActiveCell.Offset(0, -1) = 0 [color=darkblue]Then[/color]
                                                [color=darkblue]If[/color] ActiveCell.Offset(0, -12) >= Time(8, 0, 0) [color=darkblue]Then[/color]
                                                                ActiveCell.FormulaR1C1 = "=RC[-2]-RC[-12]"
                                                [color=darkblue]If[/color] ActiveCell.Offset(0, -12) < Time(8, 0, 0) [color=darkblue]Then[/color]
                                                                ActiveCell.FormulaR1C1 = "=(RC[-2]-RC[-12])+(TIME(8,0,0)-RC[-12])"
                                [color=darkblue]If[/color] ActiveCell.Offset(0, -1) >= 1 [color=darkblue]Then[/color]
                                                [color=darkblue]If[/color] ActiveCell.Offset(0, -12) > Time(18, 0, 0) [color=darkblue]Then[/color]
                                                             ActiveCell.FormulaR1C1 = "=RC[-2]-TIME(8,0,0)"
                                                [color=darkblue]If[/color] ActiveCell.Offset(0, -12) <= Time(18, 0, 0) [color=darkblue]Then[/color]
                                                                ActiveCell.FormulaR1C1 = "=(TIME(18,0,0)-RC[-12])+(RC[-2]-TIME(8,0,0))"
                                                                 
                [color=darkblue]End[/color] [color=darkblue]If[/color]
                
                                [color=darkblue]End[/color] [color=darkblue]If[/color]
                                                [color=darkblue]End[/color] [color=darkblue]If[/color]
                                                [color=darkblue]End[/color] [color=darkblue]If[/color]
                                [color=darkblue]End[/color] [color=darkblue]If[/color]
                                                [color=darkblue]End[/color] [color=darkblue]If[/color]
                                                [color=darkblue]End[/color] [color=darkblue]If[/color]
                                [color=darkblue]End[/color] [color=darkblue]If[/color]
                                                [color=darkblue]End[/color] [color=darkblue]If[/color]
                                                [color=darkblue]End[/color] [color=darkblue]If[/color]
                                                    
    
                [color=darkblue]End[/color] [color=darkblue]If[/color]
                                [color=darkblue]End[/color] [color=darkblue]If[/color]
                                [color=darkblue]End[/color] [color=darkblue]If[/color]
                                                [color=darkblue]End[/color] [color=darkblue]If[/color]
                                                [color=darkblue]End[/color] [color=darkblue]If[/color]
                                [color=darkblue]End[/color] [color=darkblue]If[/color]
                                                [color=darkblue]End[/color] [color=darkblue]If[/color]
                                                [color=darkblue]End[/color] [color=darkblue]If[/color]
       
Line4:
     ActiveCell.Offset(1, 0).Select
    x = x + 1
[color=darkblue]Loop[/color] [color=darkblue]Until[/color] Cells(x, Column).Value = ""
[/face]


Thanks :)
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
The VBA Time function takes no arguments and returns the current time. See the TimeSerial function, or just use constants:

Code:
If ActiveCell.Offset(0, -12).Value >= #8:00:00 AM# Then
 
Upvote 0
Thanks shg, I ended up changing all the Time to TimeSerial and it worked a treat. So easy when you know so frustrating when you don't.

Now I just have to get all the calculations correct.


Thanks again :)
 
Upvote 0

Forum statistics

Threads
1,224,603
Messages
6,179,854
Members
452,948
Latest member
UsmanAli786

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