VBA to hide rows in one sheet based on entries and calculation in other sheets

rgarrity

New Member
Joined
Mar 3, 2017
Messages
20
I have workbook with three sheets. The first sheet is designed for a user to enter data on a vehicle subject to a casualty loss. The second sheet calculates value of the vehicle at the time of the loss. This residual value is calculated on two different methods. The third sheet performs calculations based on the residual value, the insurance settlement, and amount needed to replace the vehicle. I need to perform one of two sets of compuations depending upon whether the insurance settlement exceeds the value of the vehicle or whether the insurance proceeds are less than the value of the vehicle at the time of loss.

I am using a worksheet event (Worksheet_Change(ByVal Target As Range)) on Sheet 1 where the insurance settlement is calculated.

VBA Code:
If Target.Address = "$C$37" Then  //Sheet1 cell where insurance settlement value is entered
    Dim RemFedInt As Long                                //Residual value
    Dim InsSettlement As Long                           //insurance settlement value
    
RemFedInt = Sheets("Computations").Range("C18").Value
InsSettlement = Sheets("Computations").Range("C20").Value

    If InsSettlement > RemFedInt Then                //If insurance exceeds residual value, show cost computations in Sheet 3 ("Settlement Details"), rows 15-38
 
       Sheets("Settlement Details").Rows("15:38").EntireRow.Hidden = False
       Sheets("Settlement Details").Rows("39:64").EntireRow.Hidden = True
    
    ElseIf InsSettlement < RemFedInt Then          //If insurance settlement is less than residual value, show cost computations in Sheet 3 ("Settlement Details"), rows 39-64
    
       Sheets("Settlement Details").Rows("15:38").EntireRow.Hidden = True
       Sheets("Settlement Details").Rows("39:64").EntireRow.Hidden = False
    
    Else                                                                 //If no value for insurance settlement, hide all computation rows 
        Sheets("Settlement Details").Rows("15:38").EntireRow.Hidden = True
        Sheets("Settlement Details").Rows("39:64").EntireRow.Hidden = True
    End If
End If

End Sub


Rows 15-64 are hidden. I do not seem to be getting any errors with the VBA code; however, regardless of the value entered in Sheet 1, cell $C$37, the rows on Sheet3 do not display. Any help would be appreciated.
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.

Forum statistics

Threads
1,223,888
Messages
6,175,219
Members
452,619
Latest member
Shiv1198

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top