This is my first attempt at using vba. What I'm trying to do is find palindromes that are multiples of three digit numbers. I figured I'd start with 100 and multiply that by 100-999 then jump to 101 times 100-999 and so on untill 999-999 and excel check each number to see if its a palindrome.
I know my code is ugly but here it is.
Sub Test2()
x = 100
y = 100
Do While x < 1000
'Starts off with x = 100
A = x * y
'multiplies x times y
b = Str(A)
c = StrReverse(A)
'converts A to a string and its reverse
'then compares the two strings
If StrComp(b, c, vbTextCompare) = 0 Then
MsgBox b
'tells me if its a palindrome
Else
End If
'Heres my problem the code goes through this loop
'but never repeats it, y goes to 1000 and stays there.
Do While y < 1000
y = y + 1
A = x * y
b = Str(A)
c = StrReverse(A)
If StrComp(b, c, vbTextCompare) = 0 Then
MsgBox b
Else
End If
Loop
x = x + 1
'adds one to x and starts loop over
Loop
End Sub
I've added some comments but they most likely make the code hard to read.
While testing this out I tossed in message boxes to see what wasnt working and it appears the my second loop only happens once.
What I dont want is a solution to how to find the palindromes, what I would like would be if someone could explain why my second loop isnt restarting.
Bookmarks