View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Barb Reinhardt Barb Reinhardt is offline
external usenet poster
 
Posts: 3,355
Default 1004 Run-Time Error


Try redomensioning Row_Count1 and 2 as Long and see if that helps.

"Satish" wrote:

Hi,

I have been at my wits end with this strange problem. I keep getting
a 1004 run-time error for the following piece of code although I dont
see anything wrong in the way I've written it.

I need to get the number of filled rows in both sheets 1 and 2. I am
running this macro on a command button in Sheet2. And the error
occurs at the line row_count1 = Worksheets(1).Range(Cells(1, 1), Cells
(1, 1).End(xlDown)).Rows.Count

If I skip that line, the row_count2 line executes perfectly fine. Both
the statements are very similar, yet I get the error. :(
Can someone please suggest some solutions?

Dim row_count1 As Integer
Dim row_count2 As Integer
Dim split_text() As String
Dim x As Integer
Dim No_Of_Elements As Integer

Worksheets(1).Activate
row_count1 = Worksheets(1).Range(Cells(1, 1), Cells(1, 1).End
(xlDown)).Rows.Count
Worksheets(2).Activate
row_count2 = Worksheets(2).Range(Cells(3, 1), Cells(3, 1).End
(xlDown)).Rows.Count

Thanks,
Satish