Code adjustment needed - vba to add values into one cell for each ID

kelly mort

Well-known Member
Joined
Apr 10, 2017
Messages
2,169
Office Version
  1. 2016
Platform
  1. Windows
This code is what I am using to get the accumulated balance.
Code:
Sub Get_bal()
    Dim acc_num As Range, lr&
    Dim db As Worksheet, val_due#, pay_mad#
    Set db = Sheets("Database")
    lr = db.Cells(Rows.Count, "A").End(xlUp).Row
    If lr < 4 Then lr = 4
    val_due = 0
    pay_mad = 0
    
    With frmData
        val_due = Application.SumIfs(db.Range("H4:H" & lr), db.Range("A4:A" & lr), .tb1.Text)
        pay_mad = Application.SumIfs(db.Range("I4:I" & lr), db.Range("A4:A" & lr), .tb1.Text)
        
        Select Case .cmb_load_invoice
            Case ""
                .tb10 = val(.tb8) - val(.tb9)
            Case Else
                .tb10 = (val_due - pay_mad) + (val(.tb8) - val(.tb9))
        End Select
    End With
End Sub

The one here is used to update data.
Code:
Set lrRng = db.Cells(Rows.Count, db.[A4].Column).End(xlUp).Offset(1)
    lrRng = tb1.Text
    
    For i = 1 To 9
        Select Case i
            Case 1
                If tb2 <> "" Then
                    lrRng.Offset(, i) = CDate(tb2.Text)
                Else
                    lrRng.Offset(, i) = ""
                End If
            Case Else
                
                lrRng.Offset(, i) = Trim(Controls("tb" & i + 1).Value)
                
        End Select
    Next i

I have this code that I am using to update my database.
Column A contain IDs and one id could exist multiple times.
The ID field is the tb1. I have been finding the accumilated balance then add it to the new record I add thhrough the update process.


My goal here is to place only on data for balance for each ID. See the image for clarity.
data_sheet-1.jpg
form_panel-1.jpg

I need a way to achieve this.

I sort data by date first then Account number all in ascending order.
Thanks for your help.
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

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