PDA

View Full Version : Caculate From One Cell & a Dimension Table



phiden
02-18-2020, 04:46 AM
Hi all,

I want to creat a function to calculate weight and thickness of a order ID (with list products).
But list of products and quantity are recorded in a cell.
Can VBA creat this function or not?

See attached file to see the details

Thank so much.

大灰狼1976
02-18-2020, 07:25 PM
Hi phiden!
Something like below.

Sub test()
Dim i&, j&, n&, arrTmp, rng As Range, rng1 As Range, strTmp$
Set rng = [a3].CurrentRegion
Application.ScreenUpdating = False
For i = 2 To rng.Rows.Count
strTmp = Replace(Replace(rng(i, 3), "(", ""), ")", ",")
arrTmp = Split(strTmp, ",")
strTmp = ""
For j = 0 To UBound(arrTmp) Step 2
Set rng1 = Columns("g").Find(arrTmp(j + 1), lookat:=xlWhole)
If Not rng1 Is Nothing Then
strTmp = strTmp & "+" & arrTmp(j) & "*H" & rng1.Row
Else
strTmp = strTmp & "+""Not Found!"""
End If
Next j
strTmp = "=" & Mid(strTmp, 2)
rng(i, 4) = strTmp
rng(i, 5) = Replace(strTmp, "H", "I")
Next i
Application.ScreenUpdating = True
End Sub