Compile Error: Object required that I can't fix

dcbuzzell

New Member
Joined
Jan 22, 2013
Messages
33
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.

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]
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Okay, I found it, and I knew it was right in front of me. Geez... must be time for vacation.

Yes, the set commands were pasted from something else I did and I did not remove them on revision. Works now.
 
Upvote 0

Forum statistics

Threads
1,214,788
Messages
6,121,600
Members
449,038
Latest member
Arbind kumar

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top