ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Looping (https://www.excelbanter.com/excel-programming/370066-looping.html)

Murph[_2_]

Looping
 
Hi Gurus
I am attempting to loop some simple code that goes down a Column A, finds
the start of a new series of up to 24 consecutive numbers, inserts two blank
rows and then continues down the next series and repeats the process.
My problem is that when it reaches the last of the series it goes back to
the start and keeps going.
Can a respondent tidy up my simple macro?
"Do
Range("Start").Select
Cells.Find(What:="01", After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _
xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlDown,
MatchCase:= _
True).Activate
ActiveCell.Range("a1").Select
ActiveCell.EntireRow.Select
Selection.Insert Shift:=xlDown
Selection.Insert Shift:=xlDown
Selection.End(xlDown).Select


Loop"

With thanks
Murph



Jim Rech

Looping
 
That's a problem with Find. You have to figure out when you've started
over. Since you're working down a column you could like:

Dim FindRow As Long

Range.Find...
If ActiveCell.Row < FindRow Then Exit Sub ''done
FindRow = ActiveCell.Row
.....

--
Jim
"Murph" wrote in message
...
| Hi Gurus
| I am attempting to loop some simple code that goes down a Column A, finds
| the start of a new series of up to 24 consecutive numbers, inserts two
blank
| rows and then continues down the next series and repeats the process.
| My problem is that when it reaches the last of the series it goes back to
| the start and keeps going.
| Can a respondent tidy up my simple macro?
| "Do
| Range("Start").Select
| Cells.Find(What:="01", After:=ActiveCell, LookIn:=xlFormulas, LookAt:=
_
| xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlDown,
| MatchCase:= _
| True).Activate
| ActiveCell.Range("a1").Select
| ActiveCell.EntireRow.Select
| Selection.Insert Shift:=xlDown
| Selection.Insert Shift:=xlDown
| Selection.End(xlDown).Select
|
|
| Loop"
|
| With thanks
| Murph
|
|



Murph[_2_]

Looping
 
Thanks for the reply Jim.
I am way behind on VB as I started via Excel 4 years ago and have not got my
head around the VB terms although I have read the books.
In this case I can't get the right syntax of:
Range.Find ("01")

My initial post may have been confusing as "Start" was the first cell in
column A with "01" and then the series went "02", "03", etc.
The data has no number format so I presume it is text I am looking for.
Are you able to put the "Range.Find" and the syntax of the declaration on
the initial macro?
At the moment I can't get the computer help files to advance my knowledge.

I am sorry if my inaptitude frustrates you.
With Thanks.




All times are GMT +1. The time now is 09:37 AM.

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