Type Mismatch

pastorkc

Board Regular
Joined
Jan 29, 2020
Messages
125
Office Version
  1. 2010
Platform
  1. Windows
If I keep getting a type mismatch error when I run my macro and it has never had it before, could it be the new data that I am importing and if so, how do I know where it is erroring out?
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
It is very likely that it could be your data.
When you get the error, do you get a "Debug" button option?
If so, click on it and see which line of code it highlights. That is where it is having issues.

Other than that, without seeing your code and sample data, there probably isn't much else we could advise you on.
 
Upvote 0
No I do not get a debug option, that was what I was hoping for so it would point me to the error. It has to be my data because the previous months ran fine. In researching I found an accounting entry this month that hasn't been done in the past so I am trying to figure out how to rectify the situation.
 
Upvote 0
How about setting a break point at the first line of the code, then stepping through your code one line at a time while watching what happens in the workbook, and see where it errors?
 
Upvote 0
I have a good idea were it is erroring, just thinking about how to fix it. It's the first time that we split an invoice onto two checks and they way the data comes over is confusing the macro when it copies the data.
 
Upvote 0
Without the details, we really cannot advise you on it, since we don't know what you are working with or trying to accomplish (in detail).
 
Upvote 0
Transit Invoice Sheet.xlsm
ABCDEFG
3590.00
360091923Invoice0919239/19/23218.71
361Payment093210/12/23-218.71
362Payment0932V10/16/23218.71
363Payment2194810/17/23-218.71
364
3650.00
Vendor Transaction History



Transit Invoice Sheet.xlsm
ABCDEFG
55389318JS23Invoice89318JS239/6/23410.00
554Payment10079/15/23-205.00
555Payment09169/15/23-205.00
Vendor Transaction History




VBA Code:
ThisWorkbook.Sheets("Vendor Transaction History").Activate
    Dim rA As Range
  
    Application.ScreenUpdating = False
    For Each rA In Range("D2", Range("D" & Rows.Count).End(xlUp)).SpecialCells(xlConstants).Areas
    With rA.Offset(, -3).Resize(, 2)
      If IsEmpty(.Cells(1, 1).Value) Then .Value = .Offset(-3).Value
    End With
    rA.Offset(, -1).Resize(, 5).Sort Key1:=rA.Columns(1), Order1:=xlAscending, Header:=xlNo
    Next rA
    Application.ScreenUpdating = True
    
    Application.ScreenUpdating = False
    Application.Calculation = xlCalculationManual

The above is were it is erroring out. The code is the section that is supposed to look and copy information, but it puts a #NA in the blank cells in the highlighted areas. Hope this helps.
 
Upvote 0
I see one potential issue. With this line here:
Rich (BB code):
For Each rA In Range("D2", Range("D" & Rows.Count).End(xlUp)).SpecialCells(xlConstants).Areas
it looks like you are starting in cell D2.

But then part of your code here:
Rich (BB code):
     If IsEmpty(.Cells(1, 1).Value) Then .Value = .Offset(-3).Value
is trying to move up 3 rows from that starting point.
If you are starting on row 2, you CANNOT move up three rows!

You can add message boxes to your code to see the addresses of the ranges while testing, i.e.
Dim rA As Range

Application.ScreenUpdating = False
Rich (BB code):
    For Each rA In Range("D2", Range("D" & Rows.Count).End(xlUp)).SpecialCells(xlConstants).Areas
        With rA.Offset(, -3).Resize(, 2)
            MsgBox .Address
            MsgBox .Offset(-3).Address
            If IsEmpty(.Cells(1, 1).Value) Then .Value = .Offset(-3).Value
        End With
        rA.Offset(, -1).Resize(, 5).Sort Key1:=rA.Columns(1), Order1:=xlAscending, Header:=xlNo
    Next rA
    
    Application.ScreenUpdating = True
    
    Application.ScreenUpdating = False
    Application.Calculation = xlCalculationManual
 
Upvote 0

Forum statistics

Threads
1,215,108
Messages
6,123,129
Members
449,097
Latest member
mlckr

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