Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reset a variable's value with a button - getting weird result

Status
Not open for further replies.

simon551

IS-IT--Management
May 4, 2005
249
I have a page that is supposed to set some cells to the values other cells. I want to be able to control setting the values back to their original values though, and override/replace what those original values are if necessary. The only part that isn't working is the part about setting the new "original" value.


This is in a module:
Code:
Sub Button18_Click()
        
        'this should be setting the value of the variables to the current content of the cells, 
'[b]but instead it is setting the value of the cells to the old value of the variable[/b] I don't understand why.
        
        OrgBaseRate = Range("BaseRate").Value
        OrgBillRate = Range("BillRate").Value
        
        Range("Update") = "<None>"   
        
End Sub
This is not:
Code:
Public OrgBaseRate As Variant
Public OrgBillRate As Variant


Private Sub Worksheet_Change(ByVal Target As Range)
On Error GoTo Skip
' The combobox is named "Update".
    If Target.Name.Name = "Update" Then
        ' Save the orginal data
        If IsEmpty(OrgBaseRate) Then OrgBaseRate = Range("BaseRate").Value
        If IsEmpty(OrgBillRate) Then OrgBillRate = Range("BillRate").Value
    
                  ' Restore the original values
                Range("BaseRate") = OrgBaseRate
                Range("BillRate") = OrgBillRate
                ' The Update combobox has changed
        Select Case Target.Value
            Case "Pay"
                Range("BaseRate") = Range("BaseRateSource").Value
                Range("BillRate") = OrgBillRate
            Case "Bill"
                Range("BillRate") = Range("BillRateSource").Value
                Range("BaseRate") = OrgBaseRate
            Case Else
                ' Restore the original values
                Range("BaseRate") = OrgBaseRate
                Range("BillRate") = OrgBillRate
        End Select
               
    End If
        If Target.Name.Name = "Target_Margin" Then Range("Update") = "<None>"
        
           
Skip:

End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top