fin_analyst
New Member
- Joined
- Dec 4, 2013
- Messages
- 2
I have read about 50 threads and cannot seem to get a macro code to work and I am not well versed in VBA so I have been trying to cut and paste certain codes to get to one that works without success.
My workbook contains an "Expense" tab and a "RPT" tab. The RPT! tab pulls data from a separate database. The goal is to have specific lines in the Expense tab hidden based on cell F3 on the expense tab which contains a formula (=right(RPT!A4,7). I tried to link the macro to the RPT!A4 but when the sheet updates from the separate database the macro errors. I should also mention that the call RPT!A4 and Expense!F3 is a number stored as text.
I learned that I can't use Worksheet_Change(ByVal Target As Range) when I am trying to run a macro triggered by a formulated cell so I am trying to use Worksheet_Calculate() but still nothing happens or it errors. I want it to run every time the number/text in Expense!F3 changes.
This is the current code I have:
Private Sub Worksheet_Calculate()
If Itersect(Target, Range("A4")) Is Nothing Then Exit Sub
If Target.Address = ("A4") And Target.Value <> "0990900" Then
Sheets("Expense").Rows("22:41,549:768").EntireRow.Hidden = True
ElseIf Target.Address = ("A4") And Target.Value = "0990900" Then
Sheets("Expense").Rows("22:41,549:768").EntireRow.Hidden = False
ElseIf Target.Address = ("A4") And Target.Value <> "6990905" Then
Sheets("Expense").Rows("46:270,372:402,813:3287,4404:4744").EntireRow.Hidden = True
ElseIf Target.Address = ("A4") And Target.Value = "6990905" Then
Sheets("Expense").Rows("46:270,372:402,813:3287,4404:4744").EntireRow.Hidden = False
End If
End Sub
Basically I want certain rows to not be visible unless the exact number/text is triggered. I have been working on this for days. Can someone please help me???
My workbook contains an "Expense" tab and a "RPT" tab. The RPT! tab pulls data from a separate database. The goal is to have specific lines in the Expense tab hidden based on cell F3 on the expense tab which contains a formula (=right(RPT!A4,7). I tried to link the macro to the RPT!A4 but when the sheet updates from the separate database the macro errors. I should also mention that the call RPT!A4 and Expense!F3 is a number stored as text.
I learned that I can't use Worksheet_Change(ByVal Target As Range) when I am trying to run a macro triggered by a formulated cell so I am trying to use Worksheet_Calculate() but still nothing happens or it errors. I want it to run every time the number/text in Expense!F3 changes.
This is the current code I have:
Private Sub Worksheet_Calculate()
If Itersect(Target, Range("A4")) Is Nothing Then Exit Sub
If Target.Address = ("A4") And Target.Value <> "0990900" Then
Sheets("Expense").Rows("22:41,549:768").EntireRow.Hidden = True
ElseIf Target.Address = ("A4") And Target.Value = "0990900" Then
Sheets("Expense").Rows("22:41,549:768").EntireRow.Hidden = False
ElseIf Target.Address = ("A4") And Target.Value <> "6990905" Then
Sheets("Expense").Rows("46:270,372:402,813:3287,4404:4744").EntireRow.Hidden = True
ElseIf Target.Address = ("A4") And Target.Value = "6990905" Then
Sheets("Expense").Rows("46:270,372:402,813:3287,4404:4744").EntireRow.Hidden = False
End If
End Sub
Basically I want certain rows to not be visible unless the exact number/text is triggered. I have been working on this for days. Can someone please help me???