+ Reply to Thread
Results 1 to 6 of 6

Use Instr to hide or show Rows based on content of cell.

  1. #1
    Forum Contributor sorensjp's Avatar
    Join Date
    12-23-2015
    Location
    Yokosuka, JP
    MS-Off Ver
    2007 and 2016
    Posts
    196

    Use Instr to hide or show Rows based on content of cell.

    Hello,

    I'm looking to improve on the code below.

    Part 1) I'm using "Instr" to hide or show specific Rows of information. The same cell to determine which Rows to hide so I use "[" or "(" identify the differences. So if either condition is not met then Rows ("11:14","16:18") should be hidden.

    Part 2) If the contents from "K7:L7" is cleared I get a "Type Mismatch" error. Which I don't knowhow to get around that.


    Please Login or Register  to view this content.
    I appreciate anyone reading this and Thank you.

    V/r,
    Jim
    Attached Files Attached Files

  2. #2
    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,411

    Re: Use Instr to hide or show Rows based on content of cell.

    Use
    Please Login or Register  to view this content.
    at the beginning of your code.
    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


  3. #3
    Forum Contributor sorensjp's Avatar
    Join Date
    12-23-2015
    Location
    Yokosuka, JP
    MS-Off Ver
    2007 and 2016
    Posts
    196

    Re: Use Instr to hide or show Rows based on content of cell.

    TMS,

    Thank you for the response. The code does work without If Target.Cells.Count > 1 Then Exit Sub.

    My goal were to not have the "Type Mismatch" error if the target cells are cleared. I'm sure my wording is convoluted in Post #1. After all I'm using American English.

    V/r,
    Jim

  4. #4
    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,411

    Re: Use Instr to hide or show Rows based on content of cell.

    When you clear multiple cells, Target is a range (of cells), not a single cell. You can't use Instr on a range; that's why you get the Type Mismatch.

    You can use

    Please Login or Register  to view this content.
    But, clearly, the Target cells will be empty so that is a waste of time. The original solution eliminates the source of the error.

    Am I missing something?

  5. #5
    Forum Contributor sorensjp's Avatar
    Join Date
    12-23-2015
    Location
    Yokosuka, JP
    MS-Off Ver
    2007 and 2016
    Posts
    196

    Re: Use Instr to hide or show Rows based on content of cell.

    TMS,

    I think your solution works well. I cannot see an issue with the results after running it through some testing.

    I appreciate your efforts.

    V/r,
    Jim

  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,411

    Re: Use Instr to hide or show Rows based on content of cell.

    You're welcome. Thanks for the rep.


    When I said, "waste of time", I’d missed the Else side of the code ... so I was wrong (but offered the correct solution)

+ 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. Hide or Show rows based off value of cell in that row?
    By dancor31 in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 05-17-2017, 01:38 PM
  2. Replies: 2
    Last Post: 09-22-2014, 12:52 PM
  3. Hide rows based on cell content using vlookup
    By jimmyhill18 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-02-2014, 11:43 PM
  4. [SOLVED] Hide/Show rows based on the value in a cell
    By PatRiot199 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 10-11-2012, 11:52 PM
  5. Hide rows based on cell content
    By garyi in forum Excel General
    Replies: 9
    Last Post: 11-14-2010, 09:10 AM
  6. Hide / Unhide rows based on cell content
    By KaFi in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 05-30-2010, 06:03 PM
  7. Replies: 2
    Last Post: 10-03-2005, 10:05 AM

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