#1   Report Post  
Derek
 
Posts: n/a
Default reverse a number

Some one may have done this but I am looking at working out palindromes on
excel and I am stuck at the first stage. I need to reverse a number value,
example 12 is 21.

Here is an example of a palindrome

87+78=165
165+561=726
726+627=1353
1353+3531=4884
  #2   Report Post  
Niek Otten
 
Posts: n/a
Default

You could use this User Defined Function (UDF)
Open the VB Editor (ALT+F11), InsertModule, and paste this code in the code
window.
You can now use the function from your worksheet

' ================================
Function ReverseNumber(a As String) As Long
Dim i As Long
Dim b As String
For i = Len(a) To 1 Step -1
b = b + Mid$(a, i, 1)
Next i
ReverseNumber = b
End Function
' ================================


--
Kind regards,

Niek Otten

Microsoft MVP - Excel

"Derek" wrote in message
...
Some one may have done this but I am looking at working out palindromes on
excel and I am stuck at the first stage. I need to reverse a number value,
example 12 is 21.

Here is an example of a palindrome

87+78=165
165+561=726
726+627=1353
1353+3531=4884



  #3   Report Post  
N Harkawat
 
Posts: n/a
Default

But if you only need a formula then
=SUMPRODUCT(--(MID(A1,ROW(INDIRECT("1:"&LEN(A1))),1)),(10^(ROW(I NDIRECT("1:"&LEN(A1))))))/10
where cell A1 holds the value to be transposed/swapped
So 561 in A1 will become 165



"Niek Otten" wrote in message
...
You could use this User Defined Function (UDF)
Open the VB Editor (ALT+F11), InsertModule, and paste this code in the
code window.
You can now use the function from your worksheet

' ================================
Function ReverseNumber(a As String) As Long
Dim i As Long
Dim b As String
For i = Len(a) To 1 Step -1
b = b + Mid$(a, i, 1)
Next i
ReverseNumber = b
End Function
' ================================


--
Kind regards,

Niek Otten

Microsoft MVP - Excel

"Derek" wrote in message
...
Some one may have done this but I am looking at working out palindromes
on
excel and I am stuck at the first stage. I need to reverse a number
value,
example 12 is 21.

Here is an example of a palindrome

87+78=165
165+561=726
726+627=1353
1353+3531=4884





  #4   Report Post  
Eamon
 
Posts: n/a
Default


Try this,
Enter with Ctrl+Shift+Enter

Enter the number you want to reverse into cell "A1" and then enter the
following array formula into cell "B1".

=SUM(VALUE(MID(A1,ROW(INDIRECT("1:"&LEN(A1))),1))* 10^(ROW(INDIRECT("1:"&LEN(A1)))-1))Eamon"Derek" wrote in ... Some one may have done this but I am looking at working out palindromes on excel and I am stuck at the first stage. I need to reverse a number value, example 12 is 21. Here is an example of a palindrome 87+78=165 165+561=726 726+627=1353 1353+3531=4884

  #5   Report Post  
Eamon
 
Posts: n/a
Default

Try this,
Enter with Ctrl+Shift+Enter

Enter the number you want to reverse into cell "A1" and then enter the
following array formula into cell "B1".

=SUM(VALUE(MID(A1,ROW(INDIRECT("1:"&LEN(A1))),1))* 10^(ROW(INDIRECT("1:"&LEN(A1)))-1))Eamon"Derek" wrote ... Some onemay have done this but I am looking at working out palindromes on excel andI am stuck at the first stage. I need to reverse a number value, example 12is 21. Here is an example of a palindrome 87+78=165 165+561=726726+627=1353 1353+3531=4884



  #6   Report Post  
Niek Otten
 
Posts: n/a
Default

Very clever! I'm afraid I'll never get the hang of SUMPRODUCT formulas,
especially those with "--"
I used to have a colleague who said "You call that clever? That's a brain
defect!" <g

--
Kind regards,

Niek Otten

Microsoft MVP - Excel

"N Harkawat" <nharkawat@hotmail_dot_com wrote in message
...
But if you only need a formula then
=SUMPRODUCT(--(MID(A1,ROW(INDIRECT("1:"&LEN(A1))),1)),(10^(ROW(I NDIRECT("1:"&LEN(A1))))))/10
where cell A1 holds the value to be transposed/swapped
So 561 in A1 will become 165



"Niek Otten" wrote in message
...
You could use this User Defined Function (UDF)
Open the VB Editor (ALT+F11), InsertModule, and paste this code in the
code window.
You can now use the function from your worksheet

' ================================
Function ReverseNumber(a As String) As Long
Dim i As Long
Dim b As String
For i = Len(a) To 1 Step -1
b = b + Mid$(a, i, 1)
Next i
ReverseNumber = b
End Function
' ================================


--
Kind regards,

Niek Otten

Microsoft MVP - Excel

"Derek" wrote in message
...
Some one may have done this but I am looking at working out palindromes
on
excel and I am stuck at the first stage. I need to reverse a number
value,
example 12 is 21.

Here is an example of a palindrome

87+78=165
165+561=726
726+627=1353
1353+3531=4884







  #7   Report Post  
Dana DeLouis
 
Posts: n/a
Default

Maybe another vba option:

Function PalindromeAdd(n)
PalindromeAdd = n + StrReverse(CStr(n))
End Function

?PalindromeAdd(1353)
4884

It's too bad they don't follow a pattern that Excel can take advantage of.
A two digit number like "ab" can be written as
(10*a + b)
So,
(10*a + b) + (10*b + a)

equals
11*(a + b)

So, a number like 87 can be calculated as:
?11*(8+7)
165

But for larger numbers, it gets too complicated, afaik.
For example, a 4 digit number "abcd" would be: 1001*(a+d) + 110*(b + c)
--
Dana DeLouis
Win XP & Office 2003


"Niek Otten" wrote in message
...
You could use this User Defined Function (UDF)
Open the VB Editor (ALT+F11), InsertModule, and paste this code in the
code window.
You can now use the function from your worksheet

' ================================
Function ReverseNumber(a As String) As Long
Dim i As Long
Dim b As String
For i = Len(a) To 1 Step -1
b = b + Mid$(a, i, 1)
Next i
ReverseNumber = b
End Function
' ================================


--
Kind regards,

Niek Otten

Microsoft MVP - Excel

"Derek" wrote in message
...
Some one may have done this but I am looking at working out palindromes
on
excel and I am stuck at the first stage. I need to reverse a number
value,
example 12 is 21.

Here is an example of a palindrome

87+78=165
165+561=726
726+627=1353
1353+3531=4884





Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
doubling a number X number of times Bob Excel Worksheet Functions 1 June 17th 05 12:54 AM
Count Number of Characters in a cell? AHJuncti Excel Discussion (Misc queries) 2 June 16th 05 07:39 PM
Need number of Saturdays and number of Sundays between 2 dates Class316 Excel Worksheet Functions 1 June 10th 05 02:47 AM
making a number be text Fredrated Excel Worksheet Functions 2 June 1st 05 02:37 AM
Need Formula or Function to calculate Margin (reverse of Percent a Ken Excel Worksheet Functions 1 February 7th 05 09:26 AM


All times are GMT +1. The time now is 10:41 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"