Hi guys,
I have a supermarket shopping list which works really well, except I have duplicated a macro six times which I call from the master macro because I don't know how to combine them all into one macro.
In column B I have six named categories (for brevity, I'll call them "Run", "Yes", "No", "Maybe", "Ok", "Righto"). Each category can appear up to 50 times in column B. What I want to do is find the first instance of one of these categories and do the following:
This macro does everything I want, but I'm trying to avoid calling it five other times. Any suggestions would be greatly appreciated:
Thanks guys,
Steve
I have a supermarket shopping list which works really well, except I have duplicated a macro six times which I call from the master macro because I don't know how to combine them all into one macro.
In column B I have six named categories (for brevity, I'll call them "Run", "Yes", "No", "Maybe", "Ok", "Righto"). Each category can appear up to 50 times in column B. What I want to do is find the first instance of one of these categories and do the following:
- Insert a blank row above
- Bold enable the first instance of the category
- Copy this first instance of the category
- Paste into Column C into the newly created blank row
This macro does everything I want, but I'm trying to avoid calling it five other times. Any suggestions would be greatly appreciated:
Code:
Sub InsertRepeat2() Dim rng As Range
rng = Sheet11.Range("T5:T10")
Dim FirstRange As Excel.Range
Sheet9.Unprotect Password:="yes"
Set rng = Sheet11.Range("B:B").Find(What:="Yes", MatchCase:=False, Lookat:=xlWhole)
Do While Not rng Is Nothing
If FirstRange Is Nothing Then
Set FirstRange = rng
Else
If rng.Address = FirstRange.Address Then
Exit Do
End If
End If
If WorksheetFunction.CountBlank(rng.Offset(0).EntireRow) <> Columns.Count Then
rng.Offset(0).EntireRow.Insert
rng.Font.Bold = True
rng.Copy
rng.Offset(-1, 1).PasteSpecial Paste:=xlPasteValues
rng.Offset(-1, 1).PasteSpecial Paste:=xlPasteFormats
Application.CutCopyMode = False
End If
Loop
Sheet9.Protect Password:="yes"
End Sub
Thanks guys,
Steve