Running Balance Calculation

AsifShah

Board Regular
Joined
Feb 12, 2021
Messages
70
Office Version
  1. 2016
  2. 2013
Platform
  1. Windows
I was Created a userform for invoice control. in this userform i was created 3 Textbox.
Textbox1 For Old Running Balance
Textbox 2 For Current Bill
Textbox 3 For Result,
If Customer running Balance in Debit then Texbox1 Value + Textbox2 Value show result in Textbox3 and if Customer Running Balance is Credit then Textbox1 Value - Textbox2 Value and show the Result in Textbox3. Please Help
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Cross-posted
 
Upvote 0
What do you mean by "Running Balance in Debit" and "Running Balance in Credit"???
Does it means Running Balance is + and Running Balance is -, respectively???
 
Upvote 0
What do you mean by "Running Balance in Debit" and "Running Balance in Credit"???
Does it means Running Balance is + and Running Balance is -, respectively???
Running Balance in Debit = " - "
Running Balance in Debit" = " + "
 
Upvote 0
Running Balance in Debit = " - "
Running Balance in Credit = " + "
What do you mean by "Running Balance in Debit" and "Running Balance in Credit"???
Does it means Running Balance is + and Running Balance is -, respectively???
 
Upvote 0
Replace your code with the one below and see if it works


VBA Code:
Private Sub Code_AfterUpdate()
'Lookup values based on first control
With Me
.Dist = Application.WorksheetFunction.VLookup(CLng(Me.Code), Sheet3.Range("Subdealer"), 2, 0)
.TextBox2 = Application.WorksheetFunction.VLookup(CLng(Me.Code), Sheet3.Range("Subdealer"), 5, 0)

End With
If TextBox1.Text = "" And TextBox2.Text < 0 Then
    TextBox3.Text = TextBox2.Text
Else
    If TextBox1.Text = "" And TextBox2.Text > 0 Then
        TextBox3.Text = TextBox2.Text
    Else
        If TextBox2.Text < 0 Then
            Label186.Caption = "Old Credit"
            TextBox3.Text = Val(TextBox1.Text) + Val(Abs(TextBox2.Text))
        Else
            Label186.Caption = "Old Debit"
            TextBox3.Text = Val(TextBox1.Text) - Val(TextBox2.Text)
        End If
    End If
End If
End Sub
 
Upvote 0
Solution
Replace your code with the one below and see if it works


VBA Code:
Private Sub Code_AfterUpdate()
'Lookup values based on first control
With Me
.Dist = Application.WorksheetFunction.VLookup(CLng(Me.Code), Sheet3.Range("Subdealer"), 2, 0)
.TextBox2 = Application.WorksheetFunction.VLookup(CLng(Me.Code), Sheet3.Range("Subdealer"), 5, 0)

End With
If TextBox1.Text = "" And TextBox2.Text < 0 Then
    TextBox3.Text = TextBox2.Text
Else
    If TextBox1.Text = "" And TextBox2.Text > 0 Then
        TextBox3.Text = TextBox2.Text
    Else
        If TextBox2.Text < 0 Then
            Label186.Caption = "Old Credit"
            TextBox3.Text = Val(TextBox1.Text) + Val(Abs(TextBox2.Text))
        Else
            Label186.Caption = "Old Debit"
            TextBox3.Text = Val(TextBox1.Text) - Val(TextBox2.Text)
        End If
    End If
End If
End Sub
Thanks Alot Brother :) Its Work for me :)
 
Upvote 0

Forum statistics

Threads
1,214,591
Messages
6,120,428
Members
448,961
Latest member
nzskater

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