Quantcast
Channel: Active questions tagged excel - Stack Overflow
Viewing all articles
Browse latest Browse all 88054

Error Occurred "Type Mismatch" whenever my macro Loop through Column A and return more than 15 match string

$
0
0

Currently I am facing an issue whenever my macro loop in through Column A to search the string "Country Code:" and it return the matched string more then 15 times . An error "Type Mismatch" would occurred. I have search through online but I could not find the solution and hope that you guys would give me an insight on what should i do

I have checked and compare my string with the raw data and it shown that there is no spelling mistake whatsoever. But i have noticed if i insert a small amount of data where the macro would return around 7 result there would be no issue.

Below is my code. I apologize for my code as i am still learning and I follow this sample online

Sub testCountryCode()
Dim ws As Worksheet
Dim toWs As Worksheet
Dim vDB, vR()
Dim i As Long, n As Long, c As Integer
Dim j As Integer

Set ws = Sheets("Database")
Set toWs = Sheets("CMF")

vDB = ws.UsedRange
c = UBound(vDB, 2)
For i = 1 To UBound(vDB, 1)
    If InStr(vDB(i, 1), "Country Code:") Then
        n = n + 1
        ReDim Preserve vR(1 To c, 1 To n)
        For j = 1 To c
            vR(j, n) = vDB(i, j)
        Next j
    End If
Next i
toWs.Range("a2").Resize(n, c) = WorksheetFunction.Transpose(vR)
Sheets("Result").Select

End Sub

Viewing all articles
Browse latest Browse all 88054

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>