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

I need help creating a macro that will search colums B for "Yes" when it
finds the first one I need a new row added above with the word "mand"
incolumn A. Then search for the first "No" in column B and do the same except
add the word Opt
Need to go from this:
tom yes
john yes
bob yes
gill yes
gail No
peter No

To this:
Mand
tom yes
john yes
bob yes
gill yes
Opt
gail No
peter No
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default Macro to insert row

With data in colA and ColB from Row1; try the below macro

Sub MyMacro()
Dim lngRow As Long, varData As Variant
lngRow = 1
Do While Range("A" & lngRow) < ""
If varData < UCase(Range("B" & lngRow)) Then
If UCase(Range("B" & lngRow)) = "YES" Then
Rows(lngRow).Insert: Range("A" & lngRow) = "mand"
lngRow = lngRow + 1
ElseIf UCase(Range("B" & lngRow)) = "NO" Then
Rows(lngRow).Insert: Range("A" & lngRow) = "Opt"
lngRow = lngRow + 1
End If
End If
varData = UCase(Range("B" & lngRow))
lngRow = lngRow + 1
Loop
End Sub
--
If this post helps click Yes
---------------
Jacob Skaria


"Bobbo" wrote:

I need help creating a macro that will search colums B for "Yes" when it
finds the first one I need a new row added above with the word "mand"
incolumn A. Then search for the first "No" in column B and do the same except
add the word Opt
Need to go from this:
tom yes
john yes
bob yes
gill yes
gail No
peter No

To this:
Mand
tom yes
john yes
bob yes
gill yes
Opt
gail No
peter No

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Macro to insert row

Give this macro a try...

Sub MandOpt()
Dim R As Range
Set R = Columns("B").Find("Yes", MatchCase:=False, LookAt:=xlWhole)
R.EntireRow.Insert xlDown
R.Offset(-1, -1).Value = "Mand"
Set R = Columns("B").Find("No", After:=R, _
MatchCase:=False, LookAt:=xlWhole)
R.EntireRow.Insert xlDown
R.Offset(-1, -1).Value = "Opt"
End Sub

--
Rick (MVP - Excel)


"Bobbo" wrote in message
...
I need help creating a macro that will search colums B for "Yes" when it
finds the first one I need a new row added above with the word "mand"
incolumn A. Then search for the first "No" in column B and do the same
except
add the word Opt
Need to go from this:
tom yes
john yes
bob yes
gill yes
gail No
peter No

To this:
Mand
tom yes
john yes
bob yes
gill yes
Opt
gail No
peter No


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
Macro to Insert Current Date into cell - Macro to "Save As" Guy[_2_] Excel Worksheet Functions 4 December 12th 08 08:20 PM
Recorded single column insert in macro. Macro inserts two not one lostatlewisu Excel Programming 3 August 16th 07 01:26 AM
make a macro to insert a macro mithu Excel Discussion (Misc queries) 6 March 20th 07 06:04 PM
Insert macro Subhojeet Excel Programming 7 October 25th 06 11:51 AM
Macro to insert copy and insert formulas only to next blank row bob Excel Programming 0 June 30th 06 12:02 PM


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