NguyenNT85
Thành viên mới

- Tham gia
- 21/1/26
- Bài viết
- 1
- Được thích
- 0



Name trong file chưa xét đến việc dữ liệu có dấu phẩy thập phân. Khi excel thiết lập dấu chấm thập phân thì lỗi.Tham khảo cách làm sau của anh @quanghai
Bạn chủ thớt nếu nuốn dùng VBA (hàm UDF) thì có thể tham khảo:
Function TongChuoi(ParamArray Vung() As Variant) As Double
Dim i&, j&, t&, k&, ktu As String, txt, Chuoi$
Dim Text As String
For t = LBound(Vung) To UBound(Vung)
For Each cell In Vung(t)
S = cell.Value
Text = ""
For i = 1 To Len(S) + 1
If i <= Len(S) Then ktu = Mid(S, i, 1)
If (ktu = " " Or ktu = ";" Or ktu = ":") Or i = Len(S) + 1 Then
If Not IsNumeric(Text) Then
For j = 1 To Len(Text)
txt = Mid(Text, j, 1): code = AscW(txt)
If code < 48 Or code > 57 Then
If MaChrW(txt) = False Then Text = Empty: k = 0: Exit For
Else
k = 1
End If
Next j
End If
Else
If ktu = "," Then ktu = "."
Text = Text & ktu
End If
If k = 1 Then
If Chuoi = Empty Then Chuoi = Text Else Chuoi = Chuoi & "+" & Text ' tong
Text = Empty: k = 0
End If
Next i
Next cell
Next t
TongChuoi = Application.Evaluate(Chuoi)
End Function
'-------
Function MaChrW(ByVal txt As String) As Boolean
Dim ops As Variant, i As Long
ops = Array("+", "-", "*", "/", "=", "%", "^", "(", ")", "[", "]", "{", "}", ".")
For i = LBound(ops) To UBound(ops)
If txt = ops(i) Then MaChrW = True: Exit For
Next i
End Function
let
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
RemovedOtherColumns = Table.SelectColumns(Source,{"BieuThuc"}),
ReplacedValue = Table.ReplaceValue(RemovedOtherColumns,",",".",Replacer.ReplaceText,{"BieuThuc"}),
CotMoi = Table.AddColumn(ReplacedValue, "KetQua", each try Expression.Evaluate([BieuThuc]) otherwise null),
SelectColumn = Table.SelectColumns(CotMoi,{"KetQua"})
in
SelectColumn