+ Reply to Thread
Results 1 to 11 of 11

Check TargetColumn, TargetValue for Text Value, copy, repeat (mismatch error)

  1. #1
    Registered User
    Join Date
    11-19-2012
    Location
    Toronto, Ontario
    MS-Off Ver
    Excel 2003
    Posts
    10

    Check TargetColumn, TargetValue for Text Value, copy, repeat (mismatch error)

    Hi all, new to vba so this may be very simple and I'm just missing it.

    In short, I'm working on a macro to check if a column in a worksheet (with a variable # of rows from day-to-day), contains one of five different text values. If it contains one of these values, then to copy the entire row to a new row on the specified page, and continue through the document.

    Example.xlsm

    The portion of code giving me trouble: -if you have a better/simpler solution, I am all ears
    (the "If TargetValue = ..." row is giving me the errors, if that helps)

    Please Login or Register  to view this content.
    Let me know what you think.
    Thanks,
    FrothyD
    Last edited by FrothyD; 10-20-2014 at 12:01 PM. Reason: Added Example Excel File

  2. #2
    Registered User
    Join Date
    10-22-2013
    Location
    Brighton, England
    MS-Off Ver
    Excel 2010
    Posts
    25

    Re: Check TargetColumn, TargetValue for Text Value, copy, repeat (mismatch error)

    Quote Originally Posted by FrothyD View Post
    Hi all, new to vba so this may be very simple and I'm just missing it.

    In short, I'm working on a macro to check if a column in a worksheet (with a variable # of rows from day-to-day), contains one of five different text values. If it contains one of these values, then to copy the entire row to a new row on the specified page, and continue through the document.

    The portion of code giving me trouble: -if you have a better/simpler solution, I am all ears
    (the "If TargetValue = ..." row is giving me the errors, if that helps)

    Sheets("Report").Select
    TargetColumn = 6
    If TargetValue = "James" Or "Mike" Or "C.H.I.C.O. Hard-Ware" Or "Rubik" Then
    Target.EntireRow.Copy _
    Destination:=Sheets("New Sheet").Range("A4" & nextRow)
    End If
    End Sub


    Let me know what you think.
    Thanks,
    FrothyD
    Please Login or Register  to view this content.
    Something like this might help. But its hard to know without seeing the workbook.

    or try Target.Value

    Kaizor

  3. #3
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,753

    Re: Check TargetColumn, TargetValue for Text Value, copy, repeat (mismatch error)

    Please use Code Tags

    You's have to say:

    Please Login or Register  to view this content.

    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  4. #4
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Check TargetColumn, TargetValue for Text Value, copy, repeat (mismatch error)

    Please comply with the Forum Rules when posting. See Rule No. 3.

    http://www.excelforum.com/forum-rule...rum-rules.html

    Does this help?

    Please Login or Register  to view this content.
    Untested try on a copy first.

  5. #5
    Registered User
    Join Date
    11-19-2012
    Location
    Toronto, Ontario
    MS-Off Ver
    Excel 2003
    Posts
    10

    Re: Check TargetColumn, TargetValue for Text Value, copy, repeat (mismatch error)

    Does this help?

    Please Login or Register  to view this content.
    Untested try on a copy first.[/QUOTE]


    Hi John, thank you for the help.

    Your code isn't causing any errors, but it also isn't grabbing any of the needed rows.

    Could you explain your logic a little more to me (I am a novice to vba)--such as what:
    Please Login or Register  to view this content.
    means? I am not quite sure what "i=2" or "End(3)" are referring to within the worksheet.

    Thanks,
    FrothyD

  6. #6
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,753

    Re: Check TargetColumn, TargetValue for Text Value, copy, repeat (mismatch error)

    Does the amendment in post #3 work? That's very basic and, if it doesn't, it would be helpful to see some sample data.


    Regards, TMS

  7. #7
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Check TargetColumn, TargetValue for Text Value, copy, repeat (mismatch error)

    "i" is a variable which starts at row 2 and goes from row 2 to the last used cell in Column 6. End(3) is a shorter version End(xlUp). This would indicate the last cell in Column 6 or "F" with data in it. However, I wasn't sure if that was what you were after.

  8. #8
    Registered User
    Join Date
    11-19-2012
    Location
    Toronto, Ontario
    MS-Off Ver
    Excel 2003
    Posts
    10

    Re: Check TargetColumn, TargetValue for Text Value, copy, repeat (mismatch error)

    Hi TMS, I tried that as well; gave no errors, but still couldn't bring in the needed rows. I've attached an example file to my original post with the data I'll be pulling from.

    Quote Originally Posted by TMS View Post
    Does the amendment in post #3 work? That's very basic and, if it doesn't, it would be helpful to see some sample data.


    Regards, TMS

  9. #9
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,753

    Re: Check TargetColumn, TargetValue for Text Value, copy, repeat (mismatch error)

    Please Login or Register  to view this content.

    If what you are trying to do is copy rows where the cells in column F are non blank, you would be better off filtering on column F and copying visible rows.

    And you could make it quicker if you built up a copy range as you go rather than copying row by row. Only important if large volumes.


    Regards, TS

  10. #10
    Registered User
    Join Date
    11-19-2012
    Location
    Toronto, Ontario
    MS-Off Ver
    Excel 2003
    Posts
    10

    Re: Check TargetColumn, TargetValue for Text Value, copy, repeat (mismatch error)

    Thank you, TS! That works perfectly.

    Cheers, and again a big thanks,
    FrothyD

  11. #11
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,753

    Re: Check TargetColumn, TargetValue for Text Value, copy, repeat (mismatch error)

    You're welcome.



    If you are satisfied with the solution(s) provided, please mark your thread as Solved.


    New quick method:
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

    Or you can use this way:

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save


    You may also want to consider thanking those people who helped you by clicking on the little star at the bottom left of their reply to your question.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [Help]Loop through the column to check date but i found "type mismatch" error
    By soldout2 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-23-2014, 10:23 PM
  2. [SOLVED] Error 13: Type MisMatch on if .value check
    By Benisato in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-18-2013, 10:41 AM
  3. Run-time error '13' Type mismatch; drag and copy
    By travis1020 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-27-2012, 02:52 PM
  4. [SOLVED] "Run-time error '13': type mismatch when running macro to add text to end of text
    By nrjordan in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-18-2012, 10:34 PM
  5. Type Mismatch error - tried .text & .value
    By Nicole Seibert in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-05-2006, 01:45 PM

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