+ Reply to Thread
Results 1 to 3 of 3

type mismatch error in code

Hybrid View

  1. #1
    Registered User
    Join Date
    08-06-2008
    Location
    Los Angeles
    Posts
    10

    type mismatch error in code

    I gave this coding thing a stab and came up with this code

    Sub promo()
    Dim LastRow As Long, i As Long, ii As Long
    LastRow = Cells(Rows.Count, "A").End(xlUp).Row
    
    For i = LastRow To 2 Step -1
     If Cells(i, "E").Value = "A" And Cells(i, "L").Value = "Incorrect creative/correct car" And Cells(i, "A").Value = "B" Then
        Cells(i, "N") = "C" And Cells(i, "M") = "D"
     End If
    unfortunately, I get an error "type mismatch" and choosing the debug option directs me to this line:

    Cells(i, "N") = "C" And Cells(i, "M") = "D"
    Oh, with the help of a friend I figured out what happened:

    "and" generally can't be placed in anything within a "then" statement. Instead I should've followed this syntax:

    Cells(i, "N") = "C"
    Cells(i, "M") = "D"
    mods: feel free to delete this if this knowledge is too basic. I don't know a lick of this coding business and made an easy goof. Thanks.
    Last edited by strikeofdawn; 08-08-2008 at 08:32 PM.

  2. #2
    Valued Forum Contributor mudraker's Avatar
    Join Date
    11-10-2003
    Location
    Melbourne, Australia
    Posts
    3,983
    Put the 2 commands on seperate lines

    For i = LastRow To 2 Step -1
     If Cells(i, "E").Value = "A" And Cells(i, "L").Value = "Incorrect creative/correct car" And Cells(i, "A").Value = "B" Then
        Cells(i, "N") = "C" 
        Cells(i, "M") = "D"
     End If
    Please Read Forum Rules Before Posting
    Wrap VBA code by selecting the code and clicking the # icon or Read This
    How To Cross Post politely

    Top Excel links for beginners to Experts

    If you are pleased with a member's answer then use the Scales icon to rate it
    If my reply has assisted or failed to assist you I welcome your Feedback.

  3. #3
    Registered User
    Join Date
    08-06-2008
    Location
    Los Angeles
    Posts
    10
    my, y'all are quick on the draw! thanks. I love this place.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1