Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 425
Default Find first and last instance of value

I want to find the instance of a value and insert a row before and one
after the last instance of the same value.

Data is in column A:G, but the value to find is always in column A.

The first value is "GroupA"
The second value is "GroupB"

Before the first instance of "GroupA", insert row and label "GroupA
Start"
After the last instance of "GroupA", insert row and label "GroupA
End".

Then the same for "GroupB".
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Find first and last instance of value

Sb AddRows()

RowCount = 1
Do while Range("A" & (RowCount + 1)) < ""
if Range("A" & RowCount) < Range("A" & (RowCount + 1)) then
Rows(RowCount + 1).Insert
RowCount = RowCount + 2
else
RowCount = RowCount + 1
end if
loop



end Sub

"J.W. Aldridge" wrote:

I want to find the instance of a value and insert a row before and one
after the last instance of the same value.

Data is in column A:G, but the value to find is always in column A.

The first value is "GroupA"
The second value is "GroupB"

Before the first instance of "GroupA", insert row and label "GroupA
Start"
After the last instance of "GroupA", insert row and label "GroupA
End".

Then the same for "GroupB".

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Find first and last instance of value

This will insert rows at the proper place:

Sub jwa()
n = Cells(Rows.Count, 1).End(xlUp).Row
For i = 1 To n
If Cells(i, 1).Value = "GroupA" Then
Cells(i, 1).EntireRow.Insert
Exit For
End If
Next
''''''''''''''''''''''''''''''''
For i = n + 1 To 1 Step -1
If Cells(i, 1).Value = "GroupA" Then
Cells(i + 1, 1).EntireRow.Insert
Exit For
End If
Next
End Sub

--
Gary''s Student - gsnu200811


"J.W. Aldridge" wrote:

I want to find the instance of a value and insert a row before and one
after the last instance of the same value.

Data is in column A:G, but the value to find is always in column A.

The first value is "GroupA"
The second value is "GroupB"

Before the first instance of "GroupA", insert row and label "GroupA
Start"
After the last instance of "GroupA", insert row and label "GroupA
End".

Then the same for "GroupB".

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
How do I find the last instance of data in a column IJ Rosenblum Excel Worksheet Functions 1 February 1st 06 08:28 PM
Find first and last instance Gixxer_J_97[_2_] Excel Programming 3 December 7th 05 07:32 PM
Find 2nd instance of a word in a range. Grumpy Grandpa Excel Worksheet Functions 8 December 5th 05 03:29 PM
Vlookup to find Second INstance [email protected] Excel Worksheet Functions 1 September 16th 05 03:33 AM
Find nth instance of a character in a string Francis Hayes (The Excel Addict) Excel Discussion (Misc queries) 7 January 21st 05 03:44 PM


All times are GMT +1. The time now is 02:54 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"