E
Eric
Hello,
I can't figure out what is wrong with the following code. Everything works,
except for the "'subs to copy utility usage data" My goal with these subs is
to copy data from one table to another. I want all changes to the data to be
immediately updated. Also the data is always entered into the table (which is
named and has 3 columns and 13 rows) on the left side of the equation to a
table on the right side of the code . I should mention that the named table
data I am copying doesn't include the table headers. I am fairly new to VBA
code, can somebody tell me where I went wrong? Here is my code:
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
'Hide/Unhide Rows when you change Utility Company on the phone script
If Not (Intersect(Target, Me.Range("vUtility_Company")) Is Nothing) Then
Select Case LCase(Me.Range("vUtility_Company").Value)
Case LCase("")
Call PS_MinimizeALL
Case LCase("PGE Residential")
Call PS_MinimizeALL
Call PGE_Res
Call PGE_Res_WriteUsage
Case LCase("PGE Business")
Call PS_MinimizeALL
Call PGE_Bus
Call PGE_Bus_WriteUsage
Case LCase("SMUD Residential")
Call PS_MinimizeALL
Call SMUD_Res
Call SMUD_Res_WriteUsage
Case LCase("Debug")
Call Show_All
Case Else
'do nothing, just continue to the end sub
End Select
Else
'Hide/Unhide Rows when you change Rent/Own Value
If Not (Intersect(Target, Me.Range("vRentOwn")) Is Nothing) Then
Select Case LCase(Me.Range("vRentOwn").Value)
Case LCase("")
Call PS_MinimizeRentOwn
Case LCase("Rent")
Call PS_MaximizeRentOwn
Case LCase("Own")
Call PS_MinimizeRentOwn
Case Else
End Select
End If
End If
End Sub
'Subs for Utility Company
Sub Show_All()
Me.Rows("30:1000").EntireRow.Hidden = False
End Sub
Sub PS_MinimizeALL()
Me.Range("vPS_MinAll_Utilities").EntireRow.Hidden = True
End Sub
Sub PGE_Res()
Me.Range("vPS_PGE_Res").EntireRow.Hidden = False
End Sub
Sub PGE_Bus()
Me.Range("vPS_PGE_Bus").EntireRow.Hidden = False
End Sub
Sub SMUD_Res()
Me.Range("vPS_SMUD_Res").EntireRow.Hidden = False
End Sub
'Subs for Rent/Own
Sub PS_MinimizeRentOwn()
Me.Range("vRentOwn_Rows").EntireRow.Hidden = True
End Sub
Sub PS_MaximizeRentOwn()
Me.Range("vRentOwn_Rows").EntireRow.Hidden = False
End Sub
'Subs for copying utility usage data
Sub PGE_Res_WriteUsage()
Me.Range("vPGE_Res_E1Usage").Value = Me.Range("vUtilityUsage_Basic").Value
End Sub
Sub PGE_Bus_WriteUsage()
Me.Range("vPGE_Bus_A1Usage").Value = Me.Range("vUtilityUsage_Basic").Value
End Sub
Sub SMUD_Res_WriteUsage()
Me.Range("vSMUD_Res_Usage").Value = Me.Range("vUtilityUsage_Basic").Value
End Sub
I can't figure out what is wrong with the following code. Everything works,
except for the "'subs to copy utility usage data" My goal with these subs is
to copy data from one table to another. I want all changes to the data to be
immediately updated. Also the data is always entered into the table (which is
named and has 3 columns and 13 rows) on the left side of the equation to a
table on the right side of the code . I should mention that the named table
data I am copying doesn't include the table headers. I am fairly new to VBA
code, can somebody tell me where I went wrong? Here is my code:
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
'Hide/Unhide Rows when you change Utility Company on the phone script
If Not (Intersect(Target, Me.Range("vUtility_Company")) Is Nothing) Then
Select Case LCase(Me.Range("vUtility_Company").Value)
Case LCase("")
Call PS_MinimizeALL
Case LCase("PGE Residential")
Call PS_MinimizeALL
Call PGE_Res
Call PGE_Res_WriteUsage
Case LCase("PGE Business")
Call PS_MinimizeALL
Call PGE_Bus
Call PGE_Bus_WriteUsage
Case LCase("SMUD Residential")
Call PS_MinimizeALL
Call SMUD_Res
Call SMUD_Res_WriteUsage
Case LCase("Debug")
Call Show_All
Case Else
'do nothing, just continue to the end sub
End Select
Else
'Hide/Unhide Rows when you change Rent/Own Value
If Not (Intersect(Target, Me.Range("vRentOwn")) Is Nothing) Then
Select Case LCase(Me.Range("vRentOwn").Value)
Case LCase("")
Call PS_MinimizeRentOwn
Case LCase("Rent")
Call PS_MaximizeRentOwn
Case LCase("Own")
Call PS_MinimizeRentOwn
Case Else
End Select
End If
End If
End Sub
'Subs for Utility Company
Sub Show_All()
Me.Rows("30:1000").EntireRow.Hidden = False
End Sub
Sub PS_MinimizeALL()
Me.Range("vPS_MinAll_Utilities").EntireRow.Hidden = True
End Sub
Sub PGE_Res()
Me.Range("vPS_PGE_Res").EntireRow.Hidden = False
End Sub
Sub PGE_Bus()
Me.Range("vPS_PGE_Bus").EntireRow.Hidden = False
End Sub
Sub SMUD_Res()
Me.Range("vPS_SMUD_Res").EntireRow.Hidden = False
End Sub
'Subs for Rent/Own
Sub PS_MinimizeRentOwn()
Me.Range("vRentOwn_Rows").EntireRow.Hidden = True
End Sub
Sub PS_MaximizeRentOwn()
Me.Range("vRentOwn_Rows").EntireRow.Hidden = False
End Sub
'Subs for copying utility usage data
Sub PGE_Res_WriteUsage()
Me.Range("vPGE_Res_E1Usage").Value = Me.Range("vUtilityUsage_Basic").Value
End Sub
Sub PGE_Bus_WriteUsage()
Me.Range("vPGE_Bus_A1Usage").Value = Me.Range("vUtilityUsage_Basic").Value
End Sub
Sub SMUD_Res_WriteUsage()
Me.Range("vSMUD_Res_Usage").Value = Me.Range("vUtilityUsage_Basic").Value
End Sub