PDA

View Full Version : edit code for display In Exponential



abbccc
04-24-2013, 11:52 PM
i find a v.b.a code for decomposition into prime
but the result is same string
i want display In Exponential Form
please edit v.b.a code or give me an other vba code

v.b.a code is


Sub Prime()
Dim n As Long, i As Long, s As String
n = ActiveCell
i = 2
Do While n >= i
If n Mod i = 0 Then
s = s & " * " & CStr(i)
n = n \ i
Else
i = i + 1
End If
Loop
ActiveCell.Offset(0, 1).Value = Mid(s, 4)
End Sub


or


Sub Prime()
Dim Number As Long
Dim Factor As Long
Number = CLng(InputBox("Enter A Number"))
Do Until Number = 1
For Factor = 2 To Number
If Number Mod Factor = 0 Then
MsgBox Factor
Number = Number / Factor
GoTo NextLoop
End If
Next Factor
NextLoop:
Loop
End Sub


for example
8 = 2^3 no 8 = 2*2*2