+ Reply to Thread
Results 1 to 8 of 8

Simple macro to group rows for a form

Hybrid View

Claudia89 Simple macro to group rows... 05-11-2014, 03:06 PM
mrice Re: Simple macro to group... 05-11-2014, 03:54 PM
Claudia89 Re: Simple macro to group... 05-11-2014, 04:22 PM
mrice Re: Simple macro to group... 05-11-2014, 04:33 PM
Claudia89 Re: Simple macro to group... 05-11-2014, 05:23 PM
mrice Re: Simple macro to group... 05-11-2014, 05:48 PM
Claudia89 Re: Simple macro to group... 05-11-2014, 06:38 PM
Claudia89 Re: Simple macro to group... 05-12-2014, 04:15 AM
  1. #1
    Registered User
    Join Date
    05-11-2014
    MS-Off Ver
    Excel 2010
    Posts
    12

    Simple macro to group rows for a form

    Hello!

    This is my first post, and I'm hoping to get some VBA help for a simple macro I wish to run (I have very little knowledge of macros).

    I am creating a new form, and have 2 option boxes. I have linked these checkboxes to a cell which gives a calculation depending on what is selected (cell E10). If the value of this cell is 2, then the person has selected that they don't need to fill in the details below. If this is the case then I would like to hid the entire rows below (rows 18 - 45 to be precise).

    At the moment I have used data validation to blank out these rows, but I'd much rather group them automatically to avoid a large gap between the option boxes and the next section. Is there a simple way to do this?

    Please let me know if I need to provide more information, or if I need to attach a copy of the spreadsheet (I'm not sure how this works).

    Thanks!

  2. #2
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967

    Re: Simple macro to group rows for a form

    Try pasting this code into the Sheet1 tab in the VBA editor (alt F11)

    Private Sub Worksheet_Calculate()
    If Range("E2") = 2 Then
        Rows("18:45").RowHeight = 0
    Else
        Rows("18:45").RowHeight = Rows(1).RowHeight
    End If
    End Sub
    Martin

  3. #3
    Registered User
    Join Date
    05-11-2014
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: Simple macro to group rows for a form

    Hi Martin,

    Thanks for the quick reply. I tried your solution above (using E10) and it did work, but when I test the option boxes it comes up with this error message:

    Run-time error '1004':

    Unable to get the RowHeight property of the Range class

    I'm not sure how to solve this problem?

  4. #4
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967

    Re: Simple macro to group rows for a form

    Can you post a copy of your workbook?

    (Go advanced and manage attachments)

  5. #5
    Registered User
    Join Date
    05-11-2014
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: Simple macro to group rows for a form

    Hi Martin,

    I've attached the form.

    Thanks for any help you can give!
    Attached Files Attached Files

  6. #6
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967

    Re: Simple macro to group rows for a form

    Please try the attachment.
    Attached Files Attached Files

  7. #7
    Registered User
    Join Date
    05-11-2014
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: Simple macro to group rows for a form

    This is great. I just amended the cell reference to E10, and it worked a treat.

    Thanks!

  8. #8
    Registered User
    Join Date
    05-11-2014
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: Simple macro to group rows for a form

    Hi again,

    Sorry but I forgot to mention, I need the spreadsheet to be protected when the macro is run (at the moment it comes up with 'run-time error 1004). Is there a way to make the macro run in password-protected spreadsheets? Perhaps an adjustment to the script?

    Thanks

+ 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. Replies: 1
    Last Post: 02-10-2014, 10:26 PM
  2. Macro to group autofilter up to 8 rows
    By Larbec in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 11-26-2013, 03:11 AM
  3. [SOLVED] Macro to group and un group rows?
    By gjjh25 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 03-06-2013, 05:13 PM
  4. Macro to form a simple report
    By Kenji in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-19-2010, 11:25 PM
  5. Group rows Macro?
    By BillXT in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 10-14-2008, 11:24 AM

Tags for this Thread

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