phamduyanh
Thành viên mới

- Tham gia
- 4/11/07
- Bài viết
- 1
- Được thích
- 1
Các bác giúp e cái ạ.
Tình hình là khi sử dụng hàm diễn giải khối lượng em gặp phải vấn đề sau:
1. Khi sử dụng hàm SQRT() thì cho kết quả: SQRTC2-2)^2+2)
2. Khi sử dụng hàm SUM() thì cho kết quả: +SUMC2
2
3.Khi sử dụng hàm TAN(), COS(), SIN() thì cho kết quả : +TANC2/180*PI
+SINC2/180*PI
+COSC2/180*PI
Bây giờ xin nhờ mọi người chỉnh lại như sau được không
1. Cần chỉnh lại để có được kết quả như sau: SQRT((12-2)^2+2) ( Giá trị ô C2=12)
2.Cần chỉnh lại hàm sum ra kết quả (+44)
( Giá trị SUMC2
2=44)
3. Cần thêm dấu () và hiển thị được giá trị của ô C2 để được kết quả như sau:
+TAN(12/180*PI)
+SINC(12/180*PI)
+COS(12/180*PI)
Em có gửi kèm file excel đi kèm đây:
Còn đây là code của chương trình: (Sưu tầm)
;;;;;;;
Function FD(mycell)
If mycell = "" Then
FD = ""
Else
If Left(mycell.Formula, 1) <> "=" Then
FD = "=Value"
Else
f = mycell.Formula
FD = f
End If
End If
Exit Function
End Function
;
Public Function Diengiai1(rngData As Range)
Dim strText As String, strText2 As String
Dim i As Long, j As Long, dem As Long
Dim subText() As String, dau() As String
Dim Res As Double
If rngData = "" Then Exit Function
strText = rngData.Formula
For i = 1 To Len(strText)
Select Case Mid(strText, i, 1)
Case "+", "-", "*", "/", "^"
ReDim Preserve dau(j)
dau(j) = Mid(strText, i, 1)
j = j + 1
End Select
Next i
strText = Replace(strText, "=", "")
strText = Replace(strText, "+", "@")
strText = Replace(strText, "-", "@")
strText = Replace(strText, "*", "@")
strText = Replace(strText, "/", "@")
strText = Replace(strText, "\", "@")
strText = Replace(strText, "^", "@")
strText = Trim(strText)
subText = Split(strText, "@")
For i = 0 To UBound(subText)
On Error Resume Next
If Not IsNumeric(subText(i)) Then
Err.Clear
Res = Application.WorksheetFunction.Find("(", subText(i))
If Err.Number = 0 Then
dem = 0
For j = 1 To Len(subText(i))
If Mid(subText(i), j, 1) = "(" Then dem = dem + 1
Next j
subText(i) = Replace(subText(i), "(", "")
If IsNumeric(subText(i)) Then
subText(i) = String(dem, "(") & subText(i)
Else
subText(i) = String(dem, "(") & Range(subText(i)).Value
End If
End If
Err.Clear
Res = Application.WorksheetFunction.Find(")", subText(i))
If Err.Number = 0 Then
dem = 0
For j = 1 To Len(subText(i))
If Mid(subText(i), j, 1) = ")" Then dem = dem + 1
Next j
subText(i) = Replace(subText(i), ")", "")
If IsNumeric(subText(i)) Then
subText(i) = subText(i) & String(dem, ")")
Else
subText(i) = Range(subText(i)).Value & String(dem, ")")
End If
End If
subText(i) = Range(subText(i)).Value
End If
Next i
ReDim Preserve dau(UBound(subText))
For i = 0 To UBound(subText)
strText2 = strText2 & subText(i) & dau(i)
Next i
Diengiai1 = strText2
End Function

Tình hình là khi sử dụng hàm diễn giải khối lượng em gặp phải vấn đề sau:
1. Khi sử dụng hàm SQRT() thì cho kết quả: SQRTC2-2)^2+2)
2. Khi sử dụng hàm SUM() thì cho kết quả: +SUMC2
3.Khi sử dụng hàm TAN(), COS(), SIN() thì cho kết quả : +TANC2/180*PI
+SINC2/180*PI
+COSC2/180*PI
Bây giờ xin nhờ mọi người chỉnh lại như sau được không

1. Cần chỉnh lại để có được kết quả như sau: SQRT((12-2)^2+2) ( Giá trị ô C2=12)
2.Cần chỉnh lại hàm sum ra kết quả (+44)
( Giá trị SUMC2
3. Cần thêm dấu () và hiển thị được giá trị của ô C2 để được kết quả như sau:
+TAN(12/180*PI)
+SINC(12/180*PI)
+COS(12/180*PI)
Em có gửi kèm file excel đi kèm đây:
Còn đây là code của chương trình: (Sưu tầm)
;;;;;;;
Function FD(mycell)
If mycell = "" Then
FD = ""
Else
If Left(mycell.Formula, 1) <> "=" Then
FD = "=Value"
Else
f = mycell.Formula
FD = f
End If
End If
Exit Function
End Function
;Public Function Diengiai1(rngData As Range)
Dim strText As String, strText2 As String
Dim i As Long, j As Long, dem As Long
Dim subText() As String, dau() As String
Dim Res As Double
If rngData = "" Then Exit Function
strText = rngData.Formula
For i = 1 To Len(strText)
Select Case Mid(strText, i, 1)
Case "+", "-", "*", "/", "^"
ReDim Preserve dau(j)
dau(j) = Mid(strText, i, 1)
j = j + 1
End Select
Next i
strText = Replace(strText, "=", "")
strText = Replace(strText, "+", "@")
strText = Replace(strText, "-", "@")
strText = Replace(strText, "*", "@")
strText = Replace(strText, "/", "@")
strText = Replace(strText, "\", "@")
strText = Replace(strText, "^", "@")
strText = Trim(strText)
subText = Split(strText, "@")
For i = 0 To UBound(subText)
On Error Resume Next
If Not IsNumeric(subText(i)) Then
Err.Clear
Res = Application.WorksheetFunction.Find("(", subText(i))
If Err.Number = 0 Then
dem = 0
For j = 1 To Len(subText(i))
If Mid(subText(i), j, 1) = "(" Then dem = dem + 1
Next j
subText(i) = Replace(subText(i), "(", "")
If IsNumeric(subText(i)) Then
subText(i) = String(dem, "(") & subText(i)
Else
subText(i) = String(dem, "(") & Range(subText(i)).Value
End If
End If
Err.Clear
Res = Application.WorksheetFunction.Find(")", subText(i))
If Err.Number = 0 Then
dem = 0
For j = 1 To Len(subText(i))
If Mid(subText(i), j, 1) = ")" Then dem = dem + 1
Next j
subText(i) = Replace(subText(i), ")", "")
If IsNumeric(subText(i)) Then
subText(i) = subText(i) & String(dem, ")")
Else
subText(i) = Range(subText(i)).Value & String(dem, ")")
End If
End If
subText(i) = Range(subText(i)).Value
End If
Next i
ReDim Preserve dau(UBound(subText))
For i = 0 To UBound(subText)
strText2 = strText2 & subText(i) & dau(i)
Next i
Diengiai1 = strText2
End Function

File đính kèm
Lần chỉnh sửa cuối:
