+ Reply to Thread
Results 1 to 6 of 6

Thread: Clearcontents when Hiding Rows

  1. #1
    Valued Forum Contributor
    Join Date
    08-19-2009
    Location
    Netherlands, Amsterdam
    MS-Off Ver
    Excel 2003
    Posts
    315

    Clearcontents when Hiding Rows

    Hello all,

    With the following code the user can, by means of a combobox, adjust the number of rows he wants to be visible [between row 8 and 17]
    i.e if the user selects 5 in the combobox, only 5 rows, starting from row 8 will be visible [row 8:12]

    Rows("8:17").Hidden = False
    Rows(Val(ComboBox1.Value) + 8 & ":17").Hidden = True
    Taking above situation as example, [the user selects 5] the user can now enter data in range G8:M12.
    When the user later adjust the number to 3 in the combobox, the data he entered in in range G10:M12 will he hidden.

    What I would like is that whenever the user adjust the number, the contents of all hidden cells is cleared [but only those in columns G:M]
    Last edited by Jonathan78; 01-27-2012 at 06:23 AM.

  2. #2
    Valued Forum Contributor
    Join Date
    08-19-2009
    Location
    Netherlands, Amsterdam
    MS-Off Ver
    Excel 2003
    Posts
    315

    Re: Clearcontents when Hiding Rows

    Impossible?

  3. #3
    Forum Moderator arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    4,399

    Re: Clearcontents when Hiding Rows

    Its possible. You have to put a "Clearcontents" code line when hiding the rows.
    So if i just add to your code above you need this line at the end -
     Rows(Val(ComboBox1.Value) + 8 & ":17").ClearContents
    Cheers,
    Arlette

    If I helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  4. #4
    Valued Forum Contributor
    Join Date
    08-19-2009
    Location
    Netherlands, Amsterdam
    MS-Off Ver
    Excel 2003
    Posts
    315

    Re: Clearcontents when Hiding Rows

    Thank you Arlu, it's almost what I need.
    But I want it to clear only the contents of the columns G:M [instead of the complete rows]

  5. #5
    Forum Moderator arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    4,399

    Re: Clearcontents when Hiding Rows

    Change the code to
     range("G" & (Val(ComboBox1.Value) + 8 & ":M17").ClearContents
    Cheers,
    Arlette

    If I helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  6. #6
    Valued Forum Contributor
    Join Date
    08-19-2009
    Location
    Netherlands, Amsterdam
    MS-Off Ver
    Excel 2003
    Posts
    315

    Re: Clearcontents when Hiding Rows

    Awesome!
    Thanks Arlu!

+ 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.2.0