Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default Using Loop to insert a row

I want to insert one row after finding a subtotal. The code below is
inserting five rows. ????
'-------------------------------------
Dim i As Integer
'i = 1
'Do Until IsEmpty(Cells(i, 1))
' Cells.Find(What:="Total", After:=ActiveCell, LookIn:=xlFormulas,
LookAt _
' :=xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext,
MatchCase:= _
' False, SearchFormat:=False).Activate
' ActiveCell.Offset(1, 0).Range("A1").Select
' Selection.EntireRow.Insert
'
'i = i + 1
'Loop
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,339
Default Using Loop to insert a row

Move these two lines AFTER the Loop statement

ActiveCell.Offset(1, 0).Range("A1").Select
Selection.EntireRow.Insert


Dim i As Integer
'i = 1
'Do Until IsEmpty(Cells(i, 1))
' Cells.Find(What:="Total", After:=ActiveCell, LookIn:=xlFormulas,
LookAt _
' :=xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext,
MatchCase:= _
' False, SearchFormat:=False).Activate
' '
'i = i + 1
'Loop


ActiveCell.Offset(1, 0).Range("A1").Select
' Selection.EntireRow.Insert



HTH


"SharonInGa" wrote:

I want to insert one row after finding a subtotal. The code below is
inserting five rows. ????
'-------------------------------------
Dim i As Integer
'i = 1
'Do Until IsEmpty(Cells(i, 1))
' Cells.Find(What:="Total", After:=ActiveCell, LookIn:=xlFormulas,
LookAt _
' :=xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext,
MatchCase:= _
' False, SearchFormat:=False).Activate
' ActiveCell.Offset(1, 0).Range("A1").Select
' Selection.EntireRow.Insert
'
'i = i + 1
'Loop

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 983
Default Using Loop to insert a row

Give this a whirl... It is more efficient and only adds the one row below the
total... I thought we already did this once? No pivot tables right...

Public Sub InsertRowAfterTotal()
Dim rngFound As Range
Dim rngToSearch As Range
Dim wksCurrent As Worksheet
Dim strFirstAddress As String

Set wksCurrent = ActiveSheet
Set rngToSearch = wksCurrent.Range("A1").EntireColumn
Set rngFound = rngToSearch.Find("Total", LookIn:=xlFormulas)

If Not rngFound Is Nothing Then
strFirstAddress = rngFound.Address
Do
rngFound.Offset(1, 0).EntireRow.Insert
Set rngFound = rngToSearch.FindNext(rngFound)
Loop While rngFound.Address < strFirstAddress
End If
End Sub

"SharonInGa" wrote:

I want to insert one row after finding a subtotal. The code below is
inserting five rows. ????
'-------------------------------------
Dim i As Integer
'i = 1
'Do Until IsEmpty(Cells(i, 1))
' Cells.Find(What:="Total", After:=ActiveCell, LookIn:=xlFormulas,
LookAt _
' :=xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext,
MatchCase:= _
' False, SearchFormat:=False).Activate
' ActiveCell.Offset(1, 0).Range("A1").Select
' Selection.EntireRow.Insert
'
'i = i + 1
'Loop

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,337
Default Using Loop to insert a row

I'm not quite sure what you want cuz I would put at the top but this code
will find the word "total" and insert a row just before that row.

Sub findtotal()
x = Columns(1).Find("total").Row
Rows(x).Insert
End Sub

this does the same
Sub findtotal1()
Rows(Columns(1).Find("total").Row).Insert
End Sub
--
Don Guillett
SalesAid Software

"SharonInGa" wrote in message
...
I want to insert one row after finding a subtotal. The code below is
inserting five rows. ????
'-------------------------------------
Dim i As Integer
'i = 1
'Do Until IsEmpty(Cells(i, 1))
' Cells.Find(What:="Total", After:=ActiveCell, LookIn:=xlFormulas,
LookAt _
' :=xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext,
MatchCase:= _
' False, SearchFormat:=False).Activate
' ActiveCell.Offset(1, 0).Range("A1").Select
' Selection.EntireRow.Insert
'
'i = i + 1
'Loop



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
Insert Variable Number of Rows; With Loop ryguy7272 Excel Worksheet Functions 2 December 27th 06 08:25 PM
loop to insert rows Fergie Excel Programming 1 November 18th 04 03:48 AM
loop to insert rows wa_hawks Excel Programming 1 October 16th 04 09:43 PM
Cant run insert row through loop WashoeJeff Excel Programming 1 January 23rd 04 12:48 PM
help on insert rows and fill down loop until end mark mcgrath Excel Programming 1 January 16th 04 01:50 AM


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

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"