Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,560
Default Loop Routine in Excel


Looking to get a macro that once it sees a variable in a particular table
inserts 3 rows and inserts two rows in the space created.

Then moves down to the next occurance of that variable and does the same-
until it reacheses the end of the file

Any help would be much appreciated
--
Thanks for your help
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Loop Routine in Excel

For i = Range("A1").End(xlDown).Row To 1 Step -1
If Cells(i,"A").alue = "the_value" Then
Rows(i+1,Resize(3).insert
End If
Next i

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"David" wrote in message
...

Looking to get a macro that once it sees a variable in a particular table
inserts 3 rows and inserts two rows in the space created.

Then moves down to the next occurance of that variable and does the same-
until it reacheses the end of the file

Any help would be much appreciated
--
Thanks for your help



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default Loop Routine in Excel

I am not to sure what you mean by "inserts 3 rows and inserts two rows in the
space created" but this will insert 3 rows at every instance of "x" in a Cell
in Column A...

Sub DeleteStuff()
Dim rngToSearch As Range
Dim rngFound As Range
Dim strFirstAddress As String

Set rngToSearch = Sheets("Sheet1").Columns("A")
Set rngFound = rngToSearch.Find(What:="x", _
LookIn:=xlFormulas, _
LookAt:=xlWhole, _
MatchCase:=False)
If rngFound Is Nothing Then
MsgBox "Sorry nothin found"
Else
strFirstAddress = rngFound.Address
Do
rngFound.Offset(1, 0).Resize(3).EntireRow.Insert
Set rngFound = rngToSearch.FindNext(rngFound)
Loop Until rngFound.Address = strFirstAddress
End If
End Sub
--
HTH...

Jim Thomlinson


"David" wrote:


Looking to get a macro that once it sees a variable in a particular table
inserts 3 rows and inserts two rows in the space created.

Then moves down to the next occurance of that variable and does the same-
until it reacheses the end of the file

Any help would be much appreciated
--
Thanks for your help

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,560
Default Loop Routine in Excel

JIm,

Thanks very much for this

The insert bit is a range of cells that needs to go in the blank cells created

e.g insert 3 rows- then copy & past a range in the first row created.

Could you help with this last bit?

Thanks again,

David

--
Thanks for your help


"Jim Thomlinson" wrote:

I am not to sure what you mean by "inserts 3 rows and inserts two rows in the
space created" but this will insert 3 rows at every instance of "x" in a Cell
in Column A...

Sub DeleteStuff()
Dim rngToSearch As Range
Dim rngFound As Range
Dim strFirstAddress As String

Set rngToSearch = Sheets("Sheet1").Columns("A")
Set rngFound = rngToSearch.Find(What:="x", _
LookIn:=xlFormulas, _
LookAt:=xlWhole, _
MatchCase:=False)
If rngFound Is Nothing Then
MsgBox "Sorry nothin found"
Else
strFirstAddress = rngFound.Address
Do
rngFound.Offset(1, 0).Resize(3).EntireRow.Insert
Set rngFound = rngToSearch.FindNext(rngFound)
Loop Until rngFound.Address = strFirstAddress
End If
End Sub
--
HTH...

Jim Thomlinson


"David" wrote:


Looking to get a macro that once it sees a variable in a particular table
inserts 3 rows and inserts two rows in the space created.

Then moves down to the next occurance of that variable and does the same-
until it reacheses the end of the file

Any help would be much appreciated
--
Thanks for your help

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
interpolation routine for Excel Steve Excel Worksheet Functions 10 November 19th 08 06:52 PM
need error loop in pivot table routine Jeff C Excel Discussion (Misc queries) 0 May 29th 08 11:08 AM
Loop routine fails after 10 cycles...... Tom Excel Programming 4 January 12th 06 03:45 AM
Excel - VBA sub routine to get AVG Excel-erate2004[_8_] Excel Programming 2 May 9th 04 09:23 PM
Help: a routine for launching an allarm in excel John Milton Excel Programming 1 September 26th 03 09:41 PM


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

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

About Us

"It's about Microsoft Excel"