Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Scan for combo then insert row

I have a worksheet sorted by Columns D, E, and G. I am trying to create a
macro that, starting in row 3, will scan every row in Columns D, E, and G for
the following combination

Column D = Sale
Column E = Purchaser
Column G = Solution

When I find the last record of this combination (Column D/Sale), (Column
E/Purchaser), (Column G/Solution) I would like to insert a row below the last
combination. Can you help me?

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,510
Default Scan for combo then insert row

Try the following.

Sub ScanCombinations()
Dim i As Long
Dim lngRow As Long

With Sheets("Sheet1")
lngRow = .Cells(.Rows.Count, "D") _
.End(xlUp).Row
End With

For i = lngRow To 3 Step -1
If Cells(i, "D") = "Sale" And _
Cells(i, "E") = "Purchaser" And _
Cells(i, "G") = "Solution" Then
Rows(i + 1).Insert
Exit Sub
End If
Next i

End Sub

--
Regards,

OssieMac


"JHopper" wrote:

I have a worksheet sorted by Columns D, E, and G. I am trying to create a
macro that, starting in row 3, will scan every row in Columns D, E, and G for
the following combination

Column D = Sale
Column E = Purchaser
Column G = Solution

When I find the last record of this combination (Column D/Sale), (Column
E/Purchaser), (Column G/Solution) I would like to insert a row below the last
combination. Can you help me?

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,510
Default Scan for combo then insert row

My previous code will work if it is the active sheet and also I forgot to
turn off CutCopyMode which will give problems if you happen to have copied
something just before running the code.

Use the following instead.

Sub ScanCombinations()
Dim i As Long
Dim lngRow As Long

Application.CutCopyMode = False

'Replace "Sheet1" with your sheet name
With Sheets("Sheet1")
lngRow = .Cells(.Rows.Count, "D") _
.End(xlUp).Row

For i = lngRow To 3 Step -1
If .Cells(i, "D") = "Sale" And _
.Cells(i, "E") = "Purchaser" And _
.Cells(i, "G") = "Solution" Then
.Rows(i + 1).Insert
Exit Sub
End If
Next i

End With
--
Regards,

OssieMac


"JHopper" wrote:

I have a worksheet sorted by Columns D, E, and G. I am trying to create a
macro that, starting in row 3, will scan every row in Columns D, E, and G for
the following combination

Column D = Sale
Column E = Purchaser
Column G = Solution

When I find the last record of this combination (Column D/Sale), (Column
E/Purchaser), (Column G/Solution) I would like to insert a row below the last
combination. Can you help me?

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Scan for combo then insert row

That's it; you nailed it! Thanks for the help OssieMac. I appreciate it.

"OssieMac" wrote:

My previous code will work if it is the active sheet and also I forgot to
turn off CutCopyMode which will give problems if you happen to have copied
something just before running the code.

Use the following instead.

Sub ScanCombinations()
Dim i As Long
Dim lngRow As Long

Application.CutCopyMode = False

'Replace "Sheet1" with your sheet name
With Sheets("Sheet1")
lngRow = .Cells(.Rows.Count, "D") _
.End(xlUp).Row

For i = lngRow To 3 Step -1
If .Cells(i, "D") = "Sale" And _
.Cells(i, "E") = "Purchaser" And _
.Cells(i, "G") = "Solution" Then
.Rows(i + 1).Insert
Exit Sub
End If
Next i

End With
--
Regards,

OssieMac


"JHopper" wrote:

I have a worksheet sorted by Columns D, E, and G. I am trying to create a
macro that, starting in row 3, will scan every row in Columns D, E, and G for
the following combination

Column D = Sale
Column E = Purchaser
Column G = Solution

When I find the last record of this combination (Column D/Sale), (Column
E/Purchaser), (Column G/Solution) I would like to insert a row below the last
combination. Can you help me?

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 combo box in a cell art Excel Discussion (Misc queries) 3 July 20th 07 04:59 PM
automatically insert date when I scan an item GregB Excel Discussion (Misc queries) 3 February 15th 07 05:47 PM
How do I insert combo drop box and still be able to sort? Anne Jett Excel Worksheet Functions 1 August 9th 05 09:57 PM
Insert Values into combo box 3Axles Excel Programming 1 May 9th 05 10:54 AM
Why can't I insert a Combo Box in Excel? mpatters Excel Discussion (Misc queries) 1 April 6th 05 11:07 PM


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