ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Find Next in a selection, how to stop it when it returns to the fi (https://www.excelbanter.com/excel-programming/305943-re-find-next-selection-how-stop-when-returns-fi.html)

Ron de Bruin

Find Next in a selection, how to stop it when it returns to the fi
 
Try this instead

Sub test()
Dim cell As Range
For Each cell In Selection.SpecialCells(xlCellTypeConstants)
If Len(cell.Value) = 1 Then
cell.Value = "'00" & cell.Value
End If
If Len(cell.Value) = 2 Then
cell.Value = "'0" & cell.Value
End If
Next cell
End Sub


--
Regards Ron de Bruin
http://www.rondebruin.nl


"Keivn Green" <Keivn wrote in message ...
I have a range of cells selected and have a find next statement to find * once it finds * it makes the cell text and fills in 0's

so that whatever number or letter it is will be 3 digits. I have the loop working but cant find a way for it to stop when the first
cell found is selected again, in other words back to the beginning.

here is what I have.
10: Selection.Find(What:="*", After:=ActiveCell, LookIn:=xlValues, LookAt:= _
xlWhole, SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:= _
False, SearchFormat:=False).Activate


Selection.NumberFormat = "@"
If Len(ActiveCell) = 1 Then
ActiveCell = "00" & ActiveCell.Text
End If
If Len(ActiveCell) = 2 Then
ActiveCell = "0" & ActiveCell.Text
End If
GoTo 10


Any ideas?





All times are GMT +1. The time now is 03:22 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com