subscript out of range error

C

cparsons

My program went down with on error in the code. I fixed that error an
tried to re-run it. When I go to re-run the program I get a subscrip
out of range error when I try to open a worksheet that I know exists.
If I close the workbook and re-open it the subscript out of range erro
doesn't show up. Below is the code.

With Worksheets("ListBox Data").Range("A2")
workbook_row_cnt = Range(.Offset(0, 0)
.End(xlDown)).Rows.Count
For i = 0 To workbook_row_cnt - 1
If .Offset(i, 0) <> "" Then
sales_group_cnt = sales_group_cnt + 1
End If
Next i
End With


I am new to this but is it recommended that a worksheet be deactivate
and then activated before each use?

You help would be appreciated.

Thank
 
D

Don Guillett

It could be as simple as you dont have the period . before
Range(.Offset(0, 0),
 
E

Earl Kiosterud

C,

I've not heard of deactivating and activating a worksheet. Just rebooting
every day or two! :)

You don't say when it starts failing again after reopening, nor which line
it's failed on. When it does, try looking at i (use a watch, or put it on
the status bar with application.statusbar = i or something.

The .Offset(0, 0) doesn't seem to be needed, and the comma after it is
suspect. Typo? You can copy code from the VBE and paste it into an email
or post, and vice versa. Just watch for line breaks.
 
C

cparsons

Turns out I had somehow added a space to the actual name on the Tab.
must have looked at it 10 times. I didn't see it until I tried t
rename the tab.

Thanks for your help
 

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