Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default Error 1004, Looping Error?

If I understand what you want to do correctly you are trying to find all
instances of 200611 and insert a blank row after them??? If so give this a
try...

Dim rngFound As Range
Dim strFirstAddress As String
Dim strFindString As String

strFindString = "200611"

With ActiveSheet.Range("B:B")
Set rngFound = .Find(What:=strFindString, _
LookIn:=xlValues, _
LookAt:=xlWhole)
If Not rngFound Is Nothing Then
'Application.Calculation = xlCalculationManual
strFirstAddress = rngFound.Address
Do
rngFound.Offset(1, 0).EntireRow.Insert
Set rngFound = .FindNext(rngFound)
Loop Until rngFound.Address = strFirstAddress
'Application.Calculation = xlCalculationAutomatic
End If
End With

If the performance of this is kinda slow then you may want to suspend
calculations while it is running (uncomment the lines)
--
HTH...

Jim Thomlinson


"shorticake" wrote:

I'm having difficulty getting this macro to loop. I keep getting the run
time error 1004, or the macro will continue to insert rows until it reaches
the last available row in the sheet.

Any help or suggestions are greatly appreciated.

Dim i As Integer
Dim Rng As Range
Dim lFirstRow As Long
With ActiveSheet.Range("B:B")

Dim findstring As String
findstring = "200611"

Set Rng = Range("B:B").Find(What:=findstring, After:=Range("B" &
Rows.Count), LookIn:=xlValues, LookAt:=xlWhole)
If Not Rng Is Nothing Then
lFirstRow = Rng.Row
Do
With Rng.Offset(1, 0)
For i = 1 To 1
.EntireRow.Insert xlShiftDown
Next i
End With
Set Rng = .FindNext(Rng)

Loop While Not Rng Is Nothing

End If
End With

End Sub

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
Error 1004, Looping Error? John Bundy Excel Programming 0 January 19th 07 11:12 PM
Error 1004, Looping Error? John Bundy Excel Programming 0 January 19th 07 11:11 PM
run-time error '1004': Application-defined or object-deifined error [email protected] Excel Programming 5 August 10th 05 09:39 PM
Excel 2003 Macro Error - Runtime error 1004 Cow Excel Discussion (Misc queries) 2 June 7th 05 01:40 PM


All times are GMT +1. The time now is 08:53 PM.

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"