match based on three comboboxes for multiple separated range from userform

Maklil

Board Regular
Joined
Jun 23, 2022
Messages
175
Office Version
  1. 2019
Platform
  1. Windows
Hi experts ,
I need matchin combobox1,2,3 with columns B:D for sheet . I want when fill data on userform combobox1,2,3 ,textbox1, then will copy to separated range is matched with combobox1,2,3 , as to textbox2 just I want showing remaining values , it depends on subtraction the value in first row from others values under first row , for instance if I write 50 in textbox1 , then textbox2 will populate value from sheet is 100- 50 which fill in textbox2 then will show 50 in textbox2 as in pic2 , if I write 20 in textbox1 then textbox2 will populate value from sheet is 100- (50+20) which fill in textbox2 then will show 30 in textbox2 as in pic4 so when show the values in textbox2 depends on first row contains value in column E subtract from aggregate under firs row .
when copy data to sheet should show the date today in column A .

MAKLIL.xlsm
ABCDE
1DATECUSTOMERINV NOITEMQTY
211/11/2022CSS-100INV-A123ITTT-100/AS-1100
3
4DATECUSTOMERINV NOITEMQTY
511/11/2022CSS-100INV-A123ITTT-100/AS-2200
6
7DATECUSTOMERINV NOITEMQTY
811/11/2022CSS-102INV-A125ITTT-100/AS-2300
9
10DATECUSTOMERINV NOITEMQTY
1111/11/2022CSS-103INV-A126ITTT-100/AS-2100
12
13DATECUSTOMERINV NOITEMQTY
1411/11/2022CSS-100INV-A124ITTT-100/AS-2200
15
16DATECUSTOMERINV NOITEMQTY
1711/11/2022CSS-105INV-A128ITTT-100/AS-6400
18
19DATECUSTOMERINV NOITEMQTY
2011/11/2022CSS-100INV-A129ITTT-100/AS-7300
DETAILS




fill the userform
2.JPG


copy to sheet for separated range
MAKLIL.xlsm
ABCDE
1DATECUSTOMERINV NOITEMQTY
211/11/2022CSS-100INV-A123ITTT-100/AS-1100
317/12/2022CSS-100INV-A123ITTT-100/AS-150
DETAILS


another process

fill userform

3.JPG




copy to sheet
MAKLIL.xlsm
ABCDE
1DATECUSTOMERINV NOITEMQTY
211/11/2022CSS-100INV-A123ITTT-100/AS-1100
317/12/2022CSS-100INV-A123ITTT-100/AS-150
417/12/2022CSS-100INV-A123ITTT-100/AS-120
DETAILS
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Is column E going to show the consumed quantity or remained quantity? In your example, it looks like showing the consumed quantity (for ex.20) but logically it should show remained quantity (30 in my opinion). Can you confirm it please?
 
Last edited by a moderator:
Upvote 0
Hi
but logically it should show remained quantity (30 in my opinion). Can you confirm it please?
sorry !!
yes you're right about (30 in my opinion)
 
Upvote 0
Then your code should look like this:
VBA Code:
Sub addItem()
  Dim lRow As Long
  Dim lValue As Variant

  lRow = Worksheets("DETAILS").Cells(Rows.Count, 1).End(xlUp).Row
  With Worksheets("DETAILS")
    For i = lRow To 2 Step-1
      If .Cells(i, 2).Value = ComboBox1.Value And .Cells(i, 3).Value = ComboBox2.Value And .Cells(i, 4).Value = ComboBox3.Value Then
        lValue = .Cells(i, 5).Value - TextBox1.Value
        TextBox2.Value = lValue
        .Cells(lRow + 1, 1).Value = Format(Now(), "dd/mm/yyyy")
        .Cells(lRow + 1, 2).Value = .Cells(i, 2).Value
        .Cells(lRow + 1, 3).Value = .Cells(i, 3).Value
        .Cells(lRow + 1, 4).Value = .Cells(i, 4).Value
        .Cells(lRow + 1, 5).Value = lValue
        Exit For
      End If
    Next
  End With
End Sub
 
Upvote 0
Hi
the code doesn't copy to sheet for separated range , what's my mistake ?
 
Upvote 0
Does the code do anything? Does it copy to somewhere else?
Maybe you should add UserForm1 object:
VBA Code:
Sub addItem()
  Dim lRow As Long
  Dim lValue As Variant

  lRow = Worksheets("DETAILS").Cells(Rows.Count, 1).End(xlUp).Row
  With Worksheets("DETAILS")
    For i = lRow To 2 Step-1
      If .Cells(i, 2).Value = UserForm1.ComboBox1.Value And .Cells(i, 3).Value = UserForm1.ComboBox2.Value And .Cells(i, 4).Value = UserForm1.ComboBox3.Value Then
        lValue = .Cells(i, 5).Value - UserForm1.TextBox1.Value
        UserForm1.TextBox2.Value = lValue
        .Cells(lRow + 1, 1).Value = Format(Now(), "dd/mm/yyyy")
        .Cells(lRow + 1, 2).Value = .Cells(i, 2).Value
        .Cells(lRow + 1, 3).Value = .Cells(i, 3).Value
        .Cells(lRow + 1, 4).Value = .Cells(i, 4).Value
        .Cells(lRow + 1, 5).Value = lValue
        Exit For
      End If
    Next
  End With
End Sub
 
Upvote 0
thanks now I see where is the problem . your code starts copying to the bottom separated ranges , but I want as the picture search for matching for three comboboxes with columns B:D in this case should fill for separated range as in picture 3,5 not copy to the bottom (should n't start after all of separated ranges).
 
Upvote 0
Then maybe something like:
VBA Code:
Sub addItem()
  Dim lRow As Long
  Dim lValue As Variant

  lRow = Worksheets("DETAILS").Cells(Rows.Count, 1).End(xlUp).Row
  With Worksheets("DETAILS")
    For i = lRow To 2 Step-1
      If .Cells(i, 2).Value = UserForm1.ComboBox1.Value And .Cells(i, 3).Value = UserForm1.ComboBox2.Value And .Cells(i, 4).Value = UserForm1.ComboBox3.Value Then
        lValue = .Cells(i, 5).Value - UserForm1.TextBox1.Value
        UserForm1.TextBox2.Value = lValue
        .Rows(i + 1).EntireRow.Insert
        .Cells(i + 1, 1).Value = Format(Now(), "dd/mm/yyyy")
        .Cells(i + 1, 2).Value = .Cells(i, 2).Value
        .Cells(i + 1, 3).Value = .Cells(i, 3).Value
        .Cells(i + 1, 4).Value = .Cells(i, 4).Value
        .Cells(i + 1, 5).Value = lValue
        Exit For
      End If
    Next
  End With
End Sub
 
Upvote 0
seem to works very well :)
just I want when add new row I want adding the borders .I tried with this line
VBA Code:
.Rows(i + 1).EntireRow.Insert CopyOrigin:=xlFormatFromRightOrAbove
but doesn't work . any idea?
 
Upvote 0
Yes, because it inserts into one row below. Which is empty.
VBA Code:
Sub addItem()
  Dim lRow As Long
  Dim lValue As Variant

  lRow = Worksheets("DETAILS").Cells(Rows.Count, 1).End(xlUp).Row
  With Worksheets("DETAILS")
    For i = lRow To 2 Step-1
      If .Cells(i, 2).Value = UserForm1.ComboBox1.Value And .Cells(i, 3).Value = UserForm1.ComboBox2.Value And .Cells(i, 4).Value = UserForm1.ComboBox3.Value Then
        lValue = .Cells(i, 5).Value - UserForm1.TextBox1.Value
        UserForm1.TextBox2.Value = lValue
        .Rows(i).EntireRow.Offset(1, 0).Insert
        .Cells(i + 1, 5).Value = lValue
        Exit For
      End If
    Next
  End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,824
Messages
6,181,186
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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