• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

What is Type Mismatch in macro

Vishal.jagani

New Member
I run macro It run successfully at one file
but again I run that macro for different files which has same columns name but sequence of column not same

at that time this error has came up and I dont know how to solve It
 
It sounds like you are trying to load Strings into a Number or vice versa

It is important in VBA that if variable are declared that they will only accept the correct data, unless they are all declared as Variants, which is real sloppy and wasteful.

If the fields are in different orders, you may have to modify your code to lookup the field location first, typically based on the fields name, before reading the data
 
This is my Macro Code

I cant see any variable declaration

Code:
Public Sub TransferData()
           Dim yesterdaysfile As Workbook, todaysfile As Workbook
           Dim yesterdaysdata As Worksheet, todaysdata As Worksheet
           Dim checkval As Boolean
          
           Set yesterdaysfile = Workbooks("File1.xlsx")
           Set todaysfile = Workbooks("File2.xlsx")
          
           lastrow = yesterdaysfile.Worksheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Row
          
           If lastrow > 1 Then
              With todaysfile.Worksheets("Sheet1")
                   .Range("A2:K" & lastrow).Insert xlShiftDown
                   Set copyrange = yesterdaysfile.Worksheets("Sheet1").Range("A2:K" & lastrow)
                   copyrange.Copy Destination:=.Range("A2")
            
                   .Range("D2:D" & lastrow).Value = 0
              End With
            
              todaysfile.Worksheets("Sheet1").Activate
              With ActiveWorkbook.ActiveSheet
                   lastrow = .Range("A" & Rows.Count).End(xlUp).Row
            
                   For i = lastrow To 2 Step -1
                       checkval = Application.Evaluate("=AND(COUNTIF($A$2:$A$" & lastrow & "," & .Cells(i, 1).Value & ") > 1, " & .Cells(i, 4).Value & " = 0)")
                       If checkval Then .Cells(i, 1).EntireRow.Delete
                   Next
              End With
           End If
End Sub
 
Which line is causing the error

ps: All the lines starting with Dim are variable declarations
 
Hello Hui,

Can we merge 2 Macro..?

I am trying to make Macro regarding some complicated process

How can we make Macro through coding as well as through Designing
I mean I don't know full of coding but I want to make macro through both of ways

I can train macro - Click on "Record macro" and I want to also done something through code by manually

Is it possible or not..?
 
Back
Top