Error 91 - Object variable with block variable not set

J

Jim

I get the above error at line:

Range(rng.Rows(startrow), rng.Rows(endrow - 1)).Delete

I wrote the code in Excel 2003 but try to run it in 97 and had to make a few

chnages. I dont know why I am getting error 91 at the above line though.



Anyone able to help? Full code posted below (its only short)



-Al







Sub Sto()

' Import Sto Data

'Sets name of file to open

FName = Application.GetOpenFilename(FileFilter:="Text File (*.txt),
FilterIndex:=2")

'Opens file with Text Wizard

Workbooks.OpenText FileName:=FName, Origin:=xlMSDOS, _ startrow:=1,
DataType:=xlFixedWidth, FieldInfo:=Array(Array(0, 1), Array(7, _ 1),
Array(14, 1), Array(28, 1), Array(36, 1), Array(39, 1), Array(42, 1),
Array(44, 1), _ Array(62, 1), Array(81, 1), Array(89, 1), Array(101, 1),
Array(104, 1), Array(110, 1), _ Array(119, 1), Array(122, 1), Array(130, 1))



' Selectsand Sorts on Column A

Columns("A:Q").Select

Selection.Sort Key1:=Range("A1"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom

Set sh = Sheets(1)

Set rng = sh.[a1].CurrentRegion

Tag = "PAGE:"

num = Application.CountIf(rng, Tag)

startrow = rng.Find(What:=Tag).Row

MsgBox startrow.Row

endrow = startrow + num

Range(rng.Rows(startrow), rng.Rows(endrow - 1)).Delete

Tag = "REG"

num = Application.CountIf(rng, Tag)

startrow = rng.Find(Tag, LookAt:=xlWhole).Row endrow = startrow + num
Range(rng.Rows(startrow), rng.Rows(endrow - 1)).Delete

Set rng = sh.[h1].CurrentRegion

Tag = "V"

num = Application.CountIf(rng, Tag)

startrow = rng.Find(Tag, LookAt:=xlWhole).Row - 1 endrow = startrow + 1000
Range(rng.Rows(startrow), rng.Rows(endrow - 1)).Delete

End Sub
 
H

Henry

Jim,

Try replacing the comma with a colon
Range is looking for something like ("A1:D77")

HTH
Henry
 
M

mudraker

you could also try



Rows(rng.Rows(startrow) & ":" & rng.Rows(endrow - 1)).Delet
Shift:=xlU
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top