INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

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

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

(OP)
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 --> vba

Sub Button18_Click()
        
        'this should be setting the value of the variables to the current content of the cells, 
'but instead it is setting the value of the cells to the old value of the variable 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 

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

Are you looking for the Excel, or maybe the VBA forum?

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

(OP)
OH. Right. Yes

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close