Type Mismatch For One Sheet

mouse88

Board Regular
Joined
May 24, 2011
Messages
148
I am using the below code. If I use it when the report sheet is selected it runs fine but if I run it when the summary sheet is selected I get the type mismatch error.

Can anyone see something im missing?

Code:
Public Sub GetData()
Call GetRanges
Dim X As Integer
Dim Y As Integer
X = 0
Y = 0
For X = 1 To UBound(AgentData)
    For Y = AgentData(X).RowStartIndex To AgentData(X).RowEndIndex
    
        If Worksheets("Report").Range("D" & Y).Text <> vbNullString Then
    
            Select Case Worksheets("Report").Range("D" & Y).Text
            
                Dim Rng As Range
            
                Case "Not_Ready_Default_Reason_Code"
                Set Rng = Range("SummaryRange").Find(AgentData(X).Name).Offset(0, 1)
                Rng.Value = TimeValue(Rng.Text) + TimeValue(Range("D" & Y).Offset(0, 2).Text)
                                
                Case "Other Admin"
                Set Rng = Range("SummaryRange").Find(AgentData(X).Name).Offset(0, 2)
                Rng.Value = TimeValue(Rng.Text) + TimeValue(Range("D" & Y).Offset(0, 2).Text)
                                
                Case "Personal"
                Set Rng = Range("SummaryRange").Find(AgentData(X).Name).Offset(0, 3)
                Rng.Value = TimeValue(Rng.Text) + TimeValue(Range("D" & Y).Offset(0, 2).Text)
                            
            End Select
    
        End If
    
    Next Y
Next X
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Try

Code:
Public Sub GetData()
Call GetRanges
Dim X As Integer
Dim Y As Integer
X = 0
Y = 0
With Worksheets("Report")
    For X = 1 To UBound(AgentData)
        For Y = AgentData(X).RowStartIndex To AgentData(X).RowEndIndex
        
            If .Range("D" & Y).Text <> vbNullString Then
        
                Select Case .Range("D" & Y).Text
                
                    Dim Rng As Range
                
                    Case "Not_Ready_Default_Reason_Code"
                    Set Rng = .Range("SummaryRange").Find(AgentData(X).Name).Offset(0, 1)
                    Rng.Value = TimeValue(Rng.Text) + TimeValue(.Range("D" & Y).Offset(0, 2).Text)
                                    
                    Case "Other Admin"
                    Set Rng = .Range("SummaryRange").Find(AgentData(X).Name).Offset(0, 2)
                    Rng.Value = TimeValue(Rng.Text) + TimeValue(.Range("D" & Y).Offset(0, 2).Text)
                                    
                    Case "Personal"
                    Set Rng = .Range("SummaryRange").Find(AgentData(X).Name).Offset(0, 3)
                    Rng.Value = TimeValue(Rng.Text) + TimeValue(.Range("D" & Y).Offset(0, 2).Text)
                                
                End Select
        
            End If
        
        Next Y
    Next X
End With
 
Upvote 0
That worked ok. Thanks.

For some reason the code is not calculating the values correctly.

The values in the report are formatted as general and in my summary table they are formatted as Time (hh:mm:ss).

Can you see anything jumping out in the code.

I have used Debug.Print to check it is looking up all the correct values and it is but somewhere along the route it is picking up extra data.

I have attached a copy of the workbook.

Thanks

http://www.megaupload.com/?d=RN2KY8B0
 
Upvote 0
Maybe you need to format the results, like this

Code:
                    Case "Not_Ready_Default_Reason_Code"
                    Set Rng = .Range("SummaryRange").Find(AgentData(X).Name).Offset(0, 1)
                    Rng.NumberFormat = "hh:mm"
                    Rng.Value = TimeValue(Rng.Text) + TimeValue(.Range("D" & Y).Offset(0, 2).Text)
 
Upvote 0
Still doesn't add up right. The very first calculation is fine but when it moves on to the next one it is wrong.
 
Upvote 0
If the values that you are looking at are times rather than text then I don't think that you need TimeValue()
 
Upvote 0
[SOLVED] Type Mismatch For One Sheet

Sorry ive just checked and they are calculating right. I was trying to add time up in my head and I was wrong.

Thanks for all your help.
 
Upvote 0

Forum statistics

Threads
1,224,552
Messages
6,179,484
Members
452,917
Latest member
MrsMSalt

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