+ Reply to Thread
Results 1 to 5 of 5

Apply formula via macro to unhide row only

Hybrid View

  1. #1
    Registered User
    Join Date
    11-27-2012
    Location
    Malaysia
    MS-Off Ver
    Excel 2003
    Posts
    66

    Post Apply formula via macro to unhide row only

    Hi,

    I'm creating an Excel Template (with vba language) which I going to use at my work place.

    Some information in attached excel file
    Excel Template.xlsm
    ComboBox - was used to hide and unhide row depend on the selection
    ActiveX Button 'Name as Update' - was use to calculate the result of cell B6 to B50 (Green Colour Merge cell) with formula

    "=SUM(RC[1]:RC[9])/SUM(R[1]C[1]:R[1]C[9])"

    Problem facing:
    1. How to edit the macro (attach with Update button) to apply formula on the unhide row only
    example: Selection "abc on combo Box" - Row 6 to 8 and row 21 to 32 was unhide (Row 9 to 20 and Row 33 to 50 was hide)

    2. When row 6 to 11 was unhide, how to teach macro to apply formula on B6, B7, B9 and B10 (but not B8 and B11 as this row as use to visually distinguish between Row 6,7 and Row 9,10).

    Thanks in Advance
    Last edited by jeffreybrown; 02-03-2013 at 12:02 PM. Reason: Please use code tags...Thanks.

  2. #2
    Forum Expert p24leclerc's Avatar
    Join Date
    07-05-2010
    Location
    Québec
    MS-Off Ver
    Excel 2021
    Posts
    2,081

    Re: Apply formula via macro to unhide row only

    This smal modification will prevent updating of hidden rows.
    See the added IF THEN condition below.
    Private Sub CommandButton1_Click()
    
    Dim lastrow As Long
    
            For rownum = 6 To 50
            If Not Cells(rownum, 2).EntireRow.Hidden Then
              Cells(rownum, 2).Formula = "=SUM(RC[1]:RC[9])/SUM(R[1]C[1]:R[1]C[9])"
            End If
            Next rownum
     
    
    End Sub
    Pierre Leclerc
    _______________________________________________________

    If you like the help you got,
    Click on the STAR "Add reputation" icon at the bottom.

  3. #3
    Registered User
    Join Date
    11-27-2012
    Location
    Malaysia
    MS-Off Ver
    Excel 2003
    Posts
    66

    Re: Apply formula via macro to unhide row only

    Thanks p24leclerc. Your IF THEN condition help me a lot.

    How about the problem statement below:

    When row 6 to 11 was unhide, how to teach macro to apply formula on B6, B7, B9 and B10 (but not B8 and B11 as this row as use to visually distinguish between Row 6,7 and Row 9,10).

  4. #4
    Forum Expert p24leclerc's Avatar
    Join Date
    07-05-2010
    Location
    Québec
    MS-Off Ver
    Excel 2021
    Posts
    2,081

    Re: Apply formula via macro to unhide row only

    you can use another If Then condition to check the interior color of the cells.
    Private Sub CommandButton1_Click()
    Dim lastrow As Long
            For rownum = 6 To 50
            If Not Cells(rownum, 2).EntireRow.Hidden Then
              asd = Cells(rownum, 2).Interior.ColorIndex
              If Cells(rownum, 2).Interior.ColorIndex = 43 Then
                Cells(rownum, 2).Formula = "=SUM(RC[1]:RC[9])/SUM(R[1]C[1]:R[1]C[9])"
              End If
            End If
            Next rownum
    End Sub

  5. #5
    Registered User
    Join Date
    11-27-2012
    Location
    Malaysia
    MS-Off Ver
    Excel 2003
    Posts
    66

    Re: Apply formula via macro to unhide row only

    thanks p24leclerc

+ 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