
Gửi bởi
zerocoldtn
Links của anh là tính tổng, cái em cần là tính từng phần ở nhiều ô (cell) như hình, và công thức sử dụng dấu "x" làm dấu nhân, các a giúp e nha!
Trong link của anh Let'GâuGâu đã có cách tính theo yêu cầu cảu bạn rùi nhé.(bài #6)
Mình góp thêm 1 ít code theo cách của mình:
sử dụng Function
Mã:
Function ValueEval(rng As String)
Dim i As Integer
Dim strTemp As String
For i = 1 To Len(rng)
Select Case Asc(Mid(rng, i, 1))
Case 40 To 45, 47 To 58, 91, 93, 120, 123, 125
ValueEval = ValueEval & Mid(rng, i, 1)
End Select
Next i
strTemp = Replace(ValueEval, "x", "*")
strTemp = Replace(strTemp, ":", "/")
strTemp = Replace(strTemp, "{", "(")
strTemp = Replace(strTemp, "}", ")")
strTemp = Replace(strTemp, "[", "(")
strTemp = Replace(strTemp, "]", ")")
strTemp = Replace(strTemp, ",", ".")
ValueEval = Evaluate(strTemp)
End Function
Chạy sub sau
Mã:
Sub run()
Dim i, pos As Integer, xau As String
For i = 8 To 23
If Cells(i, 4) = "" Then
If Cells(i, 5) <> "" Then
pos = InStr(1, Cells(i, 5), ":")
xau = Mid(Cells(i, 5), pos + 1, Len(Cells(i, 5)))
xau = ValueEval(xau)
Cells(i, 5) = Cells(i, 5) & " = " & xau
End If
If Cells(i, 62) <> "" Then
pos = InStr(1, Cells(i, 62), ":")
xau = Mid(Cells(i, 62), pos + 1, Len(Cells(i, 62)))
xau = ValueEval(xau)
Cells(i, 62) = Cells(i, 62) & " = " & xau
End If
End If
Next
End Sub