transfer data from userform by matching items in combobox with headers in sheet

Omar M

Board Regular
Joined
Jan 11, 2024
Messages
66
Office Version
  1. 2019
Platform
  1. Windows
Hi
I have comboboxex (from1 : 7) under ACCOUNT NAME , and textboxes under DEBIT (from 1:7) , under credit (from 8:14)
and textbox15 under descriptions
here is form
CM.PNG


the data in sheet


ACCOUNTS DAILY.xlsm
ABCDEFGHIJKLMNOPQRSTUVWX
1DATECONSTRAIN NODESCRIPTIONBALANCING CASETOTALBANKSAFEPURCHASESELLINGCAPITALPURCHASE RETURNINGSELLING RETURNINGRECEIVABLECREDITOR
2DEBITCREDITDEBITCREDITDEBITCREDITDEBITCREDITDEBITCREDITDEBITCREDITDEBITCREDITDEBITCREDITDEBITCREDITDEBITCREDIT
3
4
5
6
7
8
sheet1




so when select item from any combobox should match with header in row1 and copy to sheet start from row 3 into debit or credit column under account name based on debit and credit in labels and account name in combobox fo form


example fill form

PP.PNG

so should be in sheet
ACCOUNTS DAILY.xlsm
ABCDEFGHIJKLMNOPQRSTUVWX
1DATECONSTRAIN NODESCRIPTIONBALANCING CASETOTALBANKSAFEPURCHASESELLINGCAPITALPURCHASE RETURNINGSELLING RETURNINGRECEIVABLECREDITOR
2DEBITCREDITDEBITCREDITDEBITCREDITDEBITCREDITDEBITCREDITDEBITCREDITDEBITCREDITDEBITCREDITDEBITCREDITDEBITCREDIT
311/08/20241DEPOSIT CAPITALBANACED2,000.002,000.002,000.002,000.00
sheet1




another example
PP1.PNG



should be in sheet

ACCOUNTS DAILY.xlsm
ABCDEFGHIJKLMNOPQRSTUVWX
1DATECONSTRAIN NODESCRIPTIONBALANCING CASETOTALBANKSAFEPURCHASESELLINGCAPITALPURCHASE RETURNINGSELLING RETURNINGRECEIVABLECREDITOR
2DEBITCREDITDEBITCREDITDEBITCREDITDEBITCREDITDEBITCREDITDEBITCREDITDEBITCREDITDEBITCREDITDEBITCREDITDEBITCREDIT
311/08/20241DEPOSIT CAPITALBANACED2,000.002,000.002,000.002,000.00
411/08/20242BUYING GOODSBANACED3,500.003,500.001,500.002,000.003,500.00
sheet1




another example
PP2.PNG


should be in sheet
ACCOUNTS DAILY.xlsm
ABCDEFGHIJKLMNOPQRSTUVWX
1DATECONSTRAIN NODESCRIPTIONBALANCING CASETOTALBANKSAFEPURCHASESELLINGCAPITALPURCHASE RETURNINGSELLING RETURNINGRECEIVABLECREDITOR
2DEBITCREDITDEBITCREDITDEBITCREDITDEBITCREDITDEBITCREDITDEBITCREDITDEBITCREDITDEBITCREDITDEBITCREDITDEBITCREDIT
311/08/20241DEPOSIT CAPITALBANACED2,000.002,000.002,000.002,000.00
411/08/20242BUYING GOODSBANACED3,500.003,500.001,500.002,000.003,500.00
511/08/20243SELLING GOODSNOT BALANCED10,000.0015,000.0010,000.0015,000.00
sheet1


when copy data to sheet should fill date in column A and increment numbers 1,2,3.. in column B as column C will copy from textbox15
as TOTAL column in sheet will sum amounts for DEBIT column in the same row , also sum amounts for credit column in the same row
if the amounts are not the same amounts in column TOTAL for DEBIT,CREDIT then will show NOT BALANCED in column D , otherwise will be BALANCED.
every time I will insert new columns by add new accounts names inside the sheet.

thanks
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Try this:

VBA Code:
Private Sub CommandButton1_Click()
  Dim sh1 As Worksheet
  Dim i As Long, lr As Long
  Dim f As Range
  Dim cmb As String
  Dim dbt As Double, cdt As Double
  Dim tbx1 As Variant, tbx2 As Variant
  
  Set sh1 = Sheets("Sheet1")
  lr = sh1.Range("E" & Rows.Count).End(3).Row + 1
  
  For i = 1 To 7
    cmb = Controls("ComboBox" & i).Value
    If cmb <> "" Then
      Set f = sh1.Range("1:1").Find(cmb, , xlValues, xlWhole, , , False)
      If Not f Is Nothing Then
        sh1.Range("A" & lr).Value = Date
        sh1.Range("B" & lr).Value = sh1.Range("B" & lr - 1).Value + 1
        sh1.Range("C" & lr).Value = TextBox15.Value
        
        tbx1 = Controls("TextBox" & i).Value
        tbx2 = Controls("TextBox" & i + 7).Value
        If tbx1 <> "" Then
          sh1.Cells(lr, f.Column).Value = CDbl(tbx1)
          dbt = dbt + CDbl(tbx1)
        End If

        If tbx2 <> "" Then
          sh1.Cells(lr, f.Column + 1).Value = CDbl(tbx2)
          cdt = cdt + CDbl(tbx2)
        End If
      End If
    End If
  Next

  If Not f Is Nothing Then
    sh1.Range("E" & lr).Value = dbt
    sh1.Range("F" & lr).Value = cdt
    sh1.Range("D" & lr).Value = IIf(dbt = cdt, "", "NOT ") & "BALANCED"
  End If

  For i = 1 To 7
    Controls("ComboBox" & i).Value = ""
    Controls("TextBox" & i).Value = ""
    Controls("TextBox" & i + 7).Value = ""
  Next
End Sub

----- --
Let me know the result and I'll get back to you as soon as I can.
Sincerely
Dante Amor
----- --
 
Upvote 0
Awesome !
can I fill comboboxexs for accounts names automatically instead of I add new accounts names manually ,please?
sorry I don't mentioned in OP .
thanks
 
Upvote 0
can I fill comboboxexs for accounts names automatically instead of I add new accounts names manually ,please?

Try this:
VBA Code:
Private Sub CommandButton1_Click()
  Dim sh1 As Worksheet
  Dim i As Long, lr As Long
  Dim f As Range
  Dim cmb As String
  Dim dbt As Double, cdt As Double
  Dim tbx1 As Variant, tbx2 As Variant
  
  Set sh1 = Sheets("Sheet1")
  lr = sh1.Range("E" & Rows.Count).End(3).Row + 1
  
  For i = 1 To 7
    cmb = Controls("ComboBox" & i).Value
    If cmb <> "" Then
      Set f = sh1.Range("1:1").Find(cmb, , xlValues, xlWhole, , , False)
      If Not f Is Nothing Then
        sh1.Range("A" & lr).Value = Date
        sh1.Range("B" & lr).Value = sh1.Range("B" & lr - 1).Value + 1
        sh1.Range("C" & lr).Value = TextBox15.Value
        
        tbx1 = Controls("TextBox" & i).Value
        tbx2 = Controls("TextBox" & i + 7).Value
        If tbx1 <> "" Then
          sh1.Cells(lr, f.Column).Value = CDbl(tbx1)
          dbt = dbt + CDbl(tbx1)
        End If

        If tbx2 <> "" Then
          sh1.Cells(lr, f.Column + 1).Value = CDbl(tbx2)
          cdt = cdt + CDbl(tbx2)
        End If
      End If
    End If
  Next

  If Not f Is Nothing Then
    sh1.Range("E" & lr).Value = dbt
    sh1.Range("F" & lr).Value = cdt
    sh1.Range("D" & lr).Value = IIf(dbt = cdt, "", "NOT ") & "BALANCED"
  End If

  For i = 1 To 7
    Controls("ComboBox" & i).Value = ""
    Controls("TextBox" & i).Value = ""
    Controls("TextBox" & i + 7).Value = ""
  Next
End Sub

Private Sub UserForm_Activate()
  Dim i As Long, j As Long, k As Long
  Dim b() As Variant
  Dim rng As Range
  
  'Change "G" for the column where the names begin
  Set rng = Range(Cells(1, "G"), Cells(1, Cells(1, Columns.Count).End(1).Column))
  ReDim b(1 To WorksheetFunction.RoundUp(rng.Columns.Count / 2, 0))
  For j = rng.Cells(1, 1).Column To rng.Cells(1, rng.Columns.Count).Column Step 2
    k = k + 1
    b(k) = Cells(1, j)
  Next
  For i = 1 To 7
    Controls("ComboBox" & i).List = b
  Next
End Sub

😇
 
Upvote 0
Solution

Forum statistics

Threads
1,223,884
Messages
6,175,175
Members
452,615
Latest member
bogeys2birdies

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