data type mismatch error when refer to Excel cell using variables

Posted on 2012-09-18
Last Modified: 2012-09-18
I have a for loop to go through the rows of a Excel sheet. If I refer to a cell like this:

If objXLBook.ActiveSheet.Range("a1").Value = TextToSearch Then
end if

If I do the same statement using variables for the A and 1 address of cell, I get a data type mismatch error. I have done coding like this before and never had any problems. maybe I am missing or forgetting something??? My code is below

Dim rownum as integer
dim colNum as string
Rownum = 1
colNum = "a"

If objXLBook.ActiveSheet.Range(colNum + rownum).Value = TextToSearch Then
end if
Question by:LeLeBrown
    LVL 33

    Accepted Solution

    Replace + with &.

    Author Comment

    That Worked.

    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    Join & Write a Comment

    Problem: You created a new custom form in Outlook for your contacts (added fields, deleted fields, changed the layout of fields, whatever) and made it the default form for contacts. The good news is that all new contacts will utilize the new form. T…
    The System Center Operations Manager 2012, known as SCOM, is a part of the Microsoft system center product that provides the user with infrastructure monitoring and application performance monitoring. SCOM monitors:   Windows or UNIX/LinuxNetwo…
    Viewers will learn the different options available in the Backstage view in Excel 2013.
    The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now