Change Total value in sheet based on deletion selected item from listbox on userform

Maklil

Board Regular
Joined
Jun 23, 2022
Messages
144
Office Version
  1. 2019
Platform
  1. Windows
Hi Guys
first thank for mr.Dante Amore for theses codes and I modfied what I need it, but I need still some fixing for two codes if anybody can help and has free time I would appreciate it.
first in DETAILS sheet contains multiple range . every range contains multiple rows and TOTAL row based on first code doesn't show the TOTAL row is relating of data in sheet when select items from combobox1: 3
what I want also show TOTAL row is relating separated range when search on userform by combobox1:3
second code when delete specific row ,then automatically change the value in TOTAL row for column E by decrease the previous value which has ever been existed (for instance let's take range A1:E6 when delete row5 then the value in TOTAL row for column E becomes (100+100)=200 , not (200+100+100)=400 should calculate after second row for each range .and if I select range A14:E17 and delete row 16 , then the value in TOTAL row for column E becomes 400 as second row .
add.xlsm
ABCDE
1DATECUSTOMERINV NOITEMQTY
211/11/2022CSS-100INV-A123ITTT-100/AS-1200
31/2/2023CSS-100INV-A123ITTT-100/AS-1100
41/2/2023CSS-100INV-A123ITTT-100/AS-1100
55/1/2023CSS-100INV-A123ITTT-100/AS-1200
6TOTAL400
7
8DATECUSTOMERINV NOITEMQTY
911/12/2022CSS-100INV-A123ITTT-100/AS-2300
101/2/2023CSS-100INV-A123ITTT-100/AS-2100
115/1/2023CSS-100INV-A123ITTT-100/AS-2100
12TOTAL200
13
14DATECUSTOMERINV NOITEMQTY
1511/13/2022CSS-102INV-A125ITTT-100/AS-2400
161/2/2023CSS-102INV-A125ITTT-100/AS-2300
17TOTAL300
DETAILS


userform
1.JPG




VBA Code:
Option Explicit


Dim a As Variant




Private Sub ComboBox3_Change()
  Call FilterData
End Sub

Sub FilterData()
  Dim txt1 As String, txt2 As String, txt3 As String
  Dim i As Long, j As Long, k As Long
  
  ListBox1.Clear
  ReDim b(1 To UBound(a, 1), 1 To UBound(a, 2))
  For i = 1 To UBound(a)
    If ComboBox1 = "" Then txt1 = a(i, 2) Else txt1 = ComboBox1
    If ComboBox2 = "" Then txt2 = a(i, 3) Else txt2 = ComboBox2
    If ComboBox3 = "" Then txt3 = a(i, 4) Else txt3 = ComboBox3
    If LCase(a(i, 2)) Like LCase(txt1) & "*" And _
       LCase(a(i, 3)) Like LCase(txt2) & "*" And _
       LCase(a(i, 4)) Like LCase(txt3) & "*" Then
      k = k + 1
      For j = 1 To 5
        b(k, j) = a(i, j)
      Next
    End If
  Next
  If k > 0 Then ListBox1.List = b
End Sub

Private Sub UserForm_Activate()
  a = Sheets("DETAILS").Range("A2:E" & Sheets("DETAILS").Range("B" & Rows.Count).End(3).Row).Value
End Sub
Private Sub ComboBox1_Change()
  
     Call FilterData
End Sub

Private Sub ComboBox2_Change()
   
     Call FilterData
End Sub



VBA Code:
Private Sub ButtonDeleteRow_Click()
  Dim i As Integer
  Application.ScreenUpdating = False
  
  If MsgBox("Are you sure you want to delete this data row?", vbYesNo + vbQuestion, "Delete Row?") = vbYes Then
    Worksheets("DETAILS").Select
    For i = Range("A" & Rows.Count).End(xlUp).Row To 1 Step -1
      If Cells(i, 1) = ListBox1.List(ListBox1.ListIndex) Then
        Rows(i).Delete
      End If
    Next i
  End If
  Application.ScreenUpdating = True
End Sub
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
for more details
when search by comboboxex should show TOTAL last row like this
1.JPG

when select item from listbox

2.JPG


and when delete from list box should be
3.JPG


and the same thing in sheet

add.xlsm
ABCDE
1DATECUSTOMERINV NOITEMQTY
211/11/2022CSS-100INV-A123ITTT-100/AS-1200
311/2/2023CSS-100INV-A123ITTT-100/AS-1100
41/2/2023CSS-100INV-A123ITTT-100/AS-1100
5TOTAL200
DETAILS


another example
4.jpg



when delete
5.JPG


add.xlsm
ABCDE
13DATECUSTOMERINV NOITEMQTY
1411/13/2022CSS-102INV-A125ITTT-100/AS-2400
15TOTAL400
DETAILS
 
Upvote 0
Welcome to the MrExcel Message Board!

Cross-posting (posting the same question in more than one forum) is not against our rules, but the method of doing so is covered by #13 of the Forum Rules.

Be sure to follow & read the link at the end of the rule too!

Cross posted at: fixing two things when try delete item from listbox on userform & change TOTAL
There is no need to repeat the link(s) provided above but if you have posted the question at other places, please provide links to those as well.

If you do cross-post in the future and also provide links, then there shouldn’t be a problem.
 
Upvote 0

Forum statistics

Threads
1,215,106
Messages
6,123,122
Members
449,096
Latest member
provoking

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