Hi guys
here my project is extemely complicated to calculate the stock across sheets by using userform
what I want :
1- when run the userform should be optionbutton(stock) default
and calculation the stock ( before calculation if there is duplicate item for each sheet alone should be merge for each duplicate item for each sheet alone based on column D except sheet FFR doesn't contains duplicate items at all ) and the formula based on sheets names for columns H,J should be( PURCHASE-SELLING +RETURNSS-RETURPP+FFR) based on column ID-CC
based on optionbutton (STOCK) take IDTR-100 as example
when merge in sheet PURCHASE= column (QTY)=90 & column (TOTAL) =10,200 as to sheet SELLING = column (QTY)=15 & column (TOTAL) =1,770 as to sheet RETURNSS column (QTY)=2 & column (TOTAL) =220 as to sheet RETURNPP column (QTY)=5 & column (TOTAL) =600 as to sheet FFR column (QTY)=200 & column (TOTAL) =24000
now the final result QTY=90-15+2-5+200=272(as show in listbox based on selected STOCK)
TOTAL=10,200-1,770+220-600+24,000=32,050(as show in listbox based on selected STOCK )
with considering there is minus values becuase there are some items are existed in some sheets but not all when implement the formula for calculation will give you minus
as to optionbutton PURCHASE
it includes three sheets when calculation (PURCHASE -RETURNPP+FFR)
take IDTR-102 as example
when merge in sheet PURCHASE= column (QTY)=5 & column (TOTAL) =500 as to sheet RETURNPP column (QTY)=4 & column (TOTAL) =400 as to sheet FFR column (QTY)=20 & column (TOTAL) =2000
the final result QTY=5-4+20=21(as show in listbox based on selected PURCHASE)
TOTAL=500-400+2000=2100 (as show in listbox based on selected PURCHASE)
as to optionbutton (SALES)
it includes two sheets when calculation (SELLING-RETURNSS)
take IDTR-110 as example
when merge in sheet SELLING = column (QTY)=0 & column (TOTAL) =0(there is not existed this item) as to sheet RETURNSS column (QTY)=10 & column (TOTAL) =3000
the final result QTY=0-10=-10(as show in listbox based on selected SALES)
TOTAL=0-3000=-3000 (as show in listbox based on selected SALES )
last thin should also after select one of them optionbutton when write the item based on column contain header ID-CC into textbox1 should filter in list box based on written into textbox1. and ignore columns CLIENT NO , INVOICE NO & PRICE when populate data in listbox .
note : each picture I did manually to understand my idea
the code
the file
search on userform (2) (1) (5).xlsm
also posted here no answering so far .
multiple optionbuttons on userform to merge multiple sheets and calculate stock
if anybody interest to help me please inform me if need more details
thanks
here my project is extemely complicated to calculate the stock across sheets by using userform
what I want :
1- when run the userform should be optionbutton(stock) default
and calculation the stock ( before calculation if there is duplicate item for each sheet alone should be merge for each duplicate item for each sheet alone based on column D except sheet FFR doesn't contains duplicate items at all ) and the formula based on sheets names for columns H,J should be( PURCHASE-SELLING +RETURNSS-RETURPP+FFR) based on column ID-CC
based on optionbutton (STOCK) take IDTR-100 as example
when merge in sheet PURCHASE= column (QTY)=90 & column (TOTAL) =10,200 as to sheet SELLING = column (QTY)=15 & column (TOTAL) =1,770 as to sheet RETURNSS column (QTY)=2 & column (TOTAL) =220 as to sheet RETURNPP column (QTY)=5 & column (TOTAL) =600 as to sheet FFR column (QTY)=200 & column (TOTAL) =24000
now the final result QTY=90-15+2-5+200=272(as show in listbox based on selected STOCK)
TOTAL=10,200-1,770+220-600+24,000=32,050(as show in listbox based on selected STOCK )
with considering there is minus values becuase there are some items are existed in some sheets but not all when implement the formula for calculation will give you minus
as to optionbutton PURCHASE
it includes three sheets when calculation (PURCHASE -RETURNPP+FFR)
take IDTR-102 as example
when merge in sheet PURCHASE= column (QTY)=5 & column (TOTAL) =500 as to sheet RETURNPP column (QTY)=4 & column (TOTAL) =400 as to sheet FFR column (QTY)=20 & column (TOTAL) =2000
the final result QTY=5-4+20=21(as show in listbox based on selected PURCHASE)
TOTAL=500-400+2000=2100 (as show in listbox based on selected PURCHASE)
as to optionbutton (SALES)
it includes two sheets when calculation (SELLING-RETURNSS)
take IDTR-110 as example
when merge in sheet SELLING = column (QTY)=0 & column (TOTAL) =0(there is not existed this item) as to sheet RETURNSS column (QTY)=10 & column (TOTAL) =3000
the final result QTY=0-10=-10(as show in listbox based on selected SALES)
TOTAL=0-3000=-3000 (as show in listbox based on selected SALES )
last thin should also after select one of them optionbutton when write the item based on column contain header ID-CC into textbox1 should filter in list box based on written into textbox1. and ignore columns CLIENT NO , INVOICE NO & PRICE when populate data in listbox .
note : each picture I did manually to understand my idea
the code
VBA Code:
Private Sub TextBox1_Change()
Call FilterData
End Sub
Private Sub TextBox2_Change()
Call FilterData
End Sub
Private Sub TextBox3_Change()
Call FilterData
End Sub
Sub FilterData()
Dim i As Long, ii As Long, n As Long
Me.ListBox1.List = a
If Me.TextBox1 = "" Then Exit Sub
With Me.ListBox1
.Clear
For i = 0 To UBound(a, 1)
If UCase$(a(i, 3)) Like UCase$(Me.TextBox1) & "*" Then
.AddItem
.List(n, 0) = n + 1
For ii = 1 To UBound(a, 2)
.List(n, ii) = a(i, ii)
Next
n = n + 1
End If
Next
End With
Dim r As Long
Dim MySum, MySum1 As Double
MySum = 0
MySum1 = 0
With ListBox1
For r = 0 To .ListCount - 1
MySum = MySum + .List(r, 7)
MySum1 = MySum1 + .List(r, 9)
Next r
End With
TextBox2.Value = Format(MySum, "#,##0.00")
TextBox3.Value = Format(MySum1, "#,##0.00")
End Sub
Private Sub UserForm_Activate()
End Sub
Private Sub UserForm_Initialize()
Dim lindex&
Dim rngDB As Range, rng As Range
Dim i, myFormat(1) As String
Dim sWidth As String
Dim vR() As Variant
Dim n As Integer
Dim myMax As Single
Set rngDB = Range("A2:J20")
For Each rng In rngDB
n = n + 1
ReDim Preserve vR(1 To n)
vR(n) = rng.EntireColumn.Width
Next rng
myMax = WorksheetFunction.Max(vR)
For i = 1 To n
vR(i) = myMax
Next i
With Sheets("purchase").Cells(1).CurrentRegion
myFormat(0) = .Cells(2, 8).NumberFormatLocal
myFormat(1) = .Cells(2, 9).NumberFormatLocal
Set rng = .Offset(1).Resize(.Rows.Count - 1)
a = .Cells(1).CurrentRegion.Value
End With
sWidth = Join(vR, ";")
Debug.Print sWidth
With ListBox1
.ColumnCount = 10
.ColumnWidths = sWidth '<~~ 63;63;63;63;63;63;63;63;63;63;63;63;63;63;63;63;63;63;63;63;63;63;63;63;63;63;63;63
.List = rng.Value
.BorderStyle = fmBorderStyleSingle
For lindex = 0 To .ListCount - 1
'.List(lindex, 0) = (Format((.List(lindex, 0)), "dd/mm/yyyy")) ' BL = dates
.List(lindex, 0) = lindex + 1
.List(lindex, 7) = Format$(.List(lindex, 7), myFormat(0))
.List(lindex, 8) = Format$(.List(lindex, 8), myFormat(1))
.List(lindex, 9) = Format$(.List(lindex, 9), myFormat(1))
Next
a = .List
'<--- this line
End With
End Sub
search on userform (2) (1) (5).xlsm
also posted here no answering so far .
multiple optionbuttons on userform to merge multiple sheets and calculate stock
if anybody interest to help me please inform me if need more details
thanks