Excelpromax123
Board Regular
- Joined
- Sep 2, 2021
- Messages
- 172
- Office Version
- 2010
- Platform
- Windows
Hello everyone. I need to correct the code below, when outputting the number to column E, change the positive number to Negative (Like the image described below). Hope everyone can help, thank you very much!
I tried to fix it like this but the code is not working properly
arr(ik, 2) = (arr(ik, 2) + CDbl(s(1))) * -1
I tried to fix it like this but the code is not working properly
arr(ik, 2) = (arr(ik, 2) + CDbl(s(1))) * -1
VBA Code:
Sub totalsum()
On Error Resume Next
Dim Dic As Object, dArr As Variant, arr As Variant, Tmp As Variant, s As Variant
Dim i As Long, J As Integer, K As Long, ik As Long, key As String, b As Long, C As Long
Set Dic = CreateObject("Scripting.dictionary")
dArr = Range("B3:B11").Value
ReDim arr(1 To UBound(dArr), 1 To 3)
For i = 1 To UBound(dArr)
Tmp = Split(dArr(i, 1), ";")
For J = LBound(Tmp) To UBound(Tmp)
s = Split(Tmp(J), "*")
If UBound(s) = 2 Then
key = s(0)
If Not Dic.Exists(key) Then
K = K + 1
Dic.Add key, K
arr(K, 1) = key
End If
ik = Dic.Item(key)
arr(ik, 2) = (arr(ik, 2) + CDbl(s(1)))
arr(ik, 3) = arr(ik, 3) + CDbl(s(2))
End If
Next J
Next i
Range("D3:E11").ClearContents
Range("D3:E11").Resize(K) = arr
End Sub
fix.xlsm
drive.google.com