I am having trouble with the following code where I get a Compile Error: Object required error on the first set command. I'm obviously missing something right in front of me, but I can't spot it. Why doesn't it like hHeader?
Thanks for looking at this.
Thanks for looking at this.
Code:
[FONT=Calibri][COLOR=#00007F]Sub[/COLOR] delHead()
[COLOR=#00007F]Dim[/COLOR] sh [COLOR=#00007F]As[/COLOR] Worksheet, lr [COLOR=#00007F]As[/COLOR] [COLOR=#00007F]Long[/COLOR], rng [COLOR=#00007F]As[/COLOR] Range, c [COLOR=#00007F]As[/COLOR] Range, hHeader [COLOR=#00007F]As[/COLOR] [COLOR=#00007F]String[/COLOR], rRows [COLOR=#00007F]As[/COLOR] [COLOR=#00007F]Integer[/COLOR]
[COLOR=#00007F]On[/COLOR] [COLOR=#00007F]Error[/COLOR] [COLOR=#00007F]Resume[/COLOR] [COLOR=#00007F]Next[/COLOR]
********Application.DisplayAlerts = [COLOR=#00007F]False[/COLOR]
************[COLOR=#00007F]Set[/COLOR] hHeader = Application.InputBox(Prompt:= _
****************"Please select the cell that leads your header or enter the contents here.", _
********************Title:="SPECIFY HEADER TITLE", Type:=2 + 8)
********** [COLOR=#00007F]Set[/COLOR] rRows = Application.InputBox(Prompt:= _
****************"Please enter the number of rows to delete in your header.", _
********************Title:="ROWS TO DELETE", Type:=1)
****[COLOR=#00007F]On[/COLOR] [COLOR=#00007F]Error[/COLOR] [COLOR=#00007F]GoTo[/COLOR] 0
********Application.DisplayAlerts = [COLOR=#00007F]True[/COLOR]
********[COLOR=#00007F]If[/COLOR] rRows < 1 [COLOR=#00007F]Then[/COLOR]
************[COLOR=#00007F]Exit[/COLOR] [COLOR=#00007F]Sub[/COLOR]
********[COLOR=#00007F]Else[/COLOR]
************[COLOR=#00007F]Set[/COLOR] sh = Sheets(1) [COLOR=#007F00]'Edit sheet name[/COLOR]
************lr = sh.Cells.Find(What:="*", After:=sh.Range("A1"), LookAt:=xlPart, LookIn:=xlFormulas, _
************SearchOrder:=xlByRows, SearchDirection:=xlPrevious, MatchCase:=False).Row
************[COLOR=#00007F]Set[/COLOR] rng = sh.Range("A1:A" & lr)
************[COLOR=#00007F]For[/COLOR] I = lr [COLOR=#00007F]To[/COLOR] 1 [COLOR=#00007F]Step[/COLOR] -1
****************[COLOR=#00007F]If[/COLOR] WorksheetFunction.CountIf(sh.Cells(I, 1).Resize(1, 50), hHeader) > 0 [COLOR=#00007F]Then[/COLOR]
********************sh.Cells(I, 1).Resize(rRows, 1).EntireRow.Delete
****************[COLOR=#00007F]End[/COLOR] [COLOR=#00007F]If[/COLOR]
************[COLOR=#00007F]Next[/COLOR]
********[COLOR=#00007F]End[/COLOR] [COLOR=#00007F]If[/COLOR]
[COLOR=#00007F]End[/COLOR] [COLOR=#00007F]Sub
[code][/COLOR][/FONT]