Type Mismatch

Frans Scheepers

Board Regular
Joined
Apr 21, 2006
Messages
127
Hi all

I have the following problem.

<b>I have this code in an Excel macro:</b>
Code:
For Each cell In [KMLData!A3.A2500]
      
        pmValid = cell.Offset(0, 4)
        pmName = cell.Offset(0, 4)
        pmLongitude = cell.Offset(0, 10)
        pmLatitude = cell.Offset(0, 11)
        pmDescription = "Region: " & cell.Offset(0, 0) & (Chr(13)) & "Required BW: " & cell.Offset(0, 6) & (Chr(13)) & "Address: " & cell.Offset(0, 7) & (Chr(13)) & "Suburb: " & cell.Offset(0, 8) & (Chr(13)) & "Town: " & cell.Offset(0, 9) & (Chr(13)) & "Site Contact: " & cell.Offset(0, 13) & (Chr(13)) & "Contact Tel: " & cell.Offset(0, 14) & (Chr(13)) & "Contact Alt Tel: " & cell.Offset(0, 15) & (Chr(13)) & "CeI Tech Resp Manager: " & cell.Offset(0, 16)
        
        If pmValid = "" Then
           Exit For
        End If
        
        'Create a placemark
        outputText = [File_details!C8] & pmName & [File_details!C9] & pmLongitude & "," & pmLatitude & [File_details!C10] & pmDescription & [File_details!C11]
        Print #1 , outputText
    
    Next
<b>And changed it to this after I duplicated the required sheets and made the adjustments to the column names:</b>
Code:
For Each cell In [KMLData (Short)!A3.A2500]
      
        pmValid = cell.Offset(0, 1)
        pmName = cell.Offset(0, 1)
        pmLongitude = cell.Offset(0, 3)
        pmLatitude = cell.Offset(0, 4)
        pmDescription = "Region: " & cell.Offset(0, 0) & (Chr(13)) & "Required BW: " & cell.Offset(0, 2)
        
        If pmValid = "" Then
        Exit For
        End If
        
        'Create a placemark
        outputText = [File_details!C8] & pmName & [File_details!C9] & pmLongitude & "," & pmLatitude & [File_details!C10] & pmDescription & [File_details!C11]
        Print #1 , outputText
    
    Next
<b><i>When executing the new macro I get a Run-time error '13': Type mismatch.</b></i>

Any idea why. When I click debug it highlights this row:
Code:
For Each cell In [KMLData (Short)!A3.A2500]

I am now at my wits end with this seemingly easy fix but cannot find the problem.
 
Last edited by a moderator:

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
Enclosing the name in single quotes would work, as would using this:

Code:
For Each cell In Sheets("KMLData (Short)").Range("A3.A2500")
 
Upvote 0

Forum statistics

Threads
1,223,894
Messages
6,175,252
Members
452,623
Latest member
Techenthusiast

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