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

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).

Forum statistics

Threads
1,215,472
Messages
6,125,007
Members
449,203
Latest member
Daymo66

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