Hello,
I have written a code whereby I am converting the formula of selected cells to round formula without having to type the entire text. I am adding a Prefix String and a Suffix string to the existing formula of the cell. I have copied the code at the end of this message.
I had assumed that all cells to round off will have formula that calculates and therefore will have a "=" to begin with and for that I was neglecting first character and retaining the rest of existing string to be accommodated between prefix and suffix string. I have also added radio buttons a my user form to make the output round off to whole number multiple of either 5 or 10.
Problem : I need to apply " if the first character of existing string is "=" then apply Mid(SelR.Formula, 2), Else if first character is not "=" use full text in the new formula with rounding off text.
I hope I am able to explain what I want.. please help me.
Thanks
I have written a code whereby I am converting the formula of selected cells to round formula without having to type the entire text. I am adding a Prefix String and a Suffix string to the existing formula of the cell. I have copied the code at the end of this message.
I had assumed that all cells to round off will have formula that calculates and therefore will have a "=" to begin with and for that I was neglecting first character and retaining the rest of existing string to be accommodated between prefix and suffix string. I have also added radio buttons a my user form to make the output round off to whole number multiple of either 5 or 10.
Problem : I need to apply " if the first character of existing string is "=" then apply Mid(SelR.Formula, 2), Else if first character is not "=" use full text in the new formula with rounding off text.
I hope I am able to explain what I want.. please help me.
Thanks
VBA Code:
Sub AddStr_Round()
Dim SelR As Range
If Fm_AddString.OpBn_5.value = True Then
X = 5
ElseIf Fm_AddString.OpBn_10.value = True Then
X = 10
End If
If Fm_AddString.OpBn_Up.value = True Then
If Fm_AddString.OpBn_5.value = True Or Fm_AddString.OpBn_10.value = True Then
Prefix = "Roundup(("
suffix = ")/" & X & ",0)*" & X
Else
Prefix = "Roundup("
suffix = ",0)"
End If
ElseIf Fm_AddString.OpBn_Dn.value = True Then
If Fm_AddString.OpBn_5.value = True Or Fm_AddString.OpBn_10.value = True Then
Prefix = "RoundDown(("
suffix = ")/" & X & ",0)*" & X
Else
Prefix = "RoundDown("
suffix = ",0)"
End If
Else
Prefix = "Round(("
Decim = InputBox("Enter Rounding To digits", "Round Formula", 0)
suffix = ")," & Decim & ")"
End If
For Each SelR In Selection
SelR.Formula = "=" & Prefix & Mid(SelR.Formula, 2) & suffix
Next
Fm_AddString.Hide
End Sub