Runtime Error 1004 - Method Rows object_global failed

tommyb

Board Regular
Joined
Aug 3, 2008
Messages
66
Hi!

Im having a very wierd problem. I've got an excel spreadsheet that has a search function on it. There is a hidden tab where all the data sits, and a visible tab with a search button where you can enter a reg of a car and it brings up details from the hidden tab.

This works perfectly when I open the excel file that is on my machine. I've put the excel file on the intranet, and to open it you click a link, and when the pop up box comes up, you click 'OPEN', and the file opens up within IE. When I try and search for a reg, I get the following error!

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:eek:ffice:eek:ffice" /><o:p>Run-time error '1004':
Method '<NAME method of>' of object '_Global' failed </o:p>

<o:p></o:p>
<o:p>Its really confusing because this didnt used to happen before.. so I cant see why there would be an error with the code because it used to work!</o:p>
<o:p></o:p>
<o:p></o:p>
<o:p>Here is my code.</o:p>
<o:p></o:p>
<o:p></o:p>
<o:p></o:p>
<o:p></o:p>
<o:p>
Code:
[COLOR=navy][FONT=Comic Sans MS]<o:p>Sub Button1_Click()[/FONT][/COLOR]
[FONT=Comic Sans MS][COLOR=navy]'Sheet module code.[/COLOR][/FONT]
[FONT=Comic Sans MS][COLOR=navy]'Find my data in the indicated range, on this sheet![/COLOR][/FONT]
[FONT=Comic Sans MS][COLOR=navy]Dim strMessage$, strTitle$, strDefault$, strShtNm$[/COLOR][/FONT]
[FONT=Comic Sans MS][COLOR=navy]Dim lngMyCol&, lngLabelRow&[/COLOR][/FONT]
[FONT=Comic Sans MS][COLOR=navy]Dim varRegID As Variant[/COLOR][/FONT]
[FONT=Comic Sans MS][COLOR=navy]Dim rngMyData As Range[/COLOR][/FONT]
[FONT=Comic Sans MS][COLOR=navy]Dim cell As Object</o:p>[/COLOR][/FONT]
[COLOR=navy][FONT=Comic Sans MS]<o:p>[/FONT][/COLOR]
[FONT=Comic Sans MS][COLOR=navy]Application.ScreenUpdating = False[/COLOR][/FONT]
 
[FONT=Comic Sans MS][COLOR=navy]strShtNm = ActiveSheet.Name[/COLOR][/FONT]
[FONT=Comic Sans MS][COLOR=navy]strMessage = "Enter ""Reg"" ID, below:" ' Set Prompt.[/COLOR][/FONT]
[FONT=Comic Sans MS][COLOR=navy]strTitle = "Find This Information!" ' Set Title.[/COLOR][/FONT]
[FONT=Comic Sans MS][COLOR=navy]strDefault = "" ' Set Default.[/COLOR][/FONT]
 
[FONT=Comic Sans MS][COLOR=navy]' Display strMessage, strTitle, and strDefault value.[/COLOR][/FONT]
[FONT=Comic Sans MS][COLOR=navy]varRegID = InputBox(strMessage, strTitle, strDefault)[/COLOR][/FONT]
[FONT=Comic Sans MS][COLOR=navy]'The row that your data's labels are in![/COLOR][/FONT]
[FONT=Comic Sans MS][COLOR=navy]lngLabelRow = 2[/COLOR][/FONT]
[FONT=Comic Sans MS][COLOR=navy]'Change below to your range, the Column to find data in![/COLOR][/FONT]
[FONT=Comic Sans MS][COLOR=navy]lngLstRow = Sheets("Sheet1").Cells(Rows.Count, 1).End(xlUp).Row[/COLOR][/FONT]
[FONT=Comic Sans MS][COLOR=navy]Sheets("Sheet1").Activate[/COLOR][/FONT]
[FONT=Comic Sans MS][COLOR=navy]Sheets("Sheet1").Range("A2:A" & lngLstRow).Activate[/COLOR][/FONT]
[FONT=Comic Sans MS][COLOR=navy]On Error GoTo myErr[/COLOR][/FONT]
[FONT=Comic Sans MS][COLOR=navy]'Find the data![/COLOR][/FONT]
[FONT=Comic Sans MS][COLOR=navy]Selection.Find(What:=varRegID, _[/COLOR][/FONT]
[FONT=Comic Sans MS][COLOR=navy]After:=ActiveCell, LookIn:=xlValues, LookAt:= _[/COLOR][/FONT]
[FONT=Comic Sans MS][COLOR=navy]xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _[/COLOR][/FONT]
[FONT=Comic Sans MS][COLOR=navy]MatchCase:=False, SearchFormat:=False).Activate[/COLOR][/FONT]
[FONT=Comic Sans MS][COLOR=navy]'Get row data![/COLOR][/FONT]
[FONT=Comic Sans MS][COLOR=navy]lngMyCol = ActiveCell.Column[/COLOR][/FONT]
[FONT=Comic Sans MS][COLOR=navy]lngMyRow = ActiveCell.Row[/COLOR][/FONT]
[FONT=Comic Sans MS][COLOR=navy]lngLstCol = Sheets("Sheet1").Cells(lngMyRow, Columns.Count).End(xlToLeft).Column[/COLOR][/FONT]
[FONT=Comic Sans MS][COLOR=navy]Set rngMyData = Sheets("Sheet1").Range(Cells(lngMyRow, 1), Cells(lngMyRow, lngLstCol))[/COLOR][/FONT]
[FONT=Comic Sans MS][COLOR=navy]For Each cell In rngMyData[/COLOR][/FONT]
[FONT=Comic Sans MS][COLOR=navy]lngLabelCol = lngLabelCol + 1[/COLOR][/FONT]
[FONT=Comic Sans MS][COLOR=navy]Sheets("Sheet2").Cells(16, lngLabelCol).Value = cell.Value[/COLOR][/FONT]
[FONT=Comic Sans MS][COLOR=navy]Next cell[/COLOR][/FONT]
[FONT=Comic Sans MS][COLOR=navy]Sheets("Sheet1").Range("A1").Activate[/COLOR][/FONT]
[FONT=Comic Sans MS][COLOR=navy]Sheets(strShtNm).Select[/COLOR][/FONT]
 
[FONT=Comic Sans MS][COLOR=navy]GoTo myEnd[/COLOR][/FONT]
[FONT=Comic Sans MS][COLOR=navy]myErr:[/COLOR][/FONT]
[FONT=Comic Sans MS][COLOR=navy]Sheets("Sheet1").Range("A1").Activate[/COLOR][/FONT]
[FONT=Comic Sans MS][COLOR=navy]Sheets(strShtNm).Select[/COLOR][/FONT]
[FONT=Comic Sans MS][COLOR=navy]MsgBox "The ""Reg"" ID:" & vbLf & vbLf & _[/COLOR][/FONT]
[FONT=Comic Sans MS][COLOR=navy]varRegID & vbLf & vbLf & _[/COLOR][/FONT]
[FONT=Comic Sans MS][COLOR=navy]"was not found!", _[/COLOR][/FONT]
[FONT=Comic Sans MS][COLOR=navy]vbCritical + vbOKOnly, _[/COLOR][/FONT]
[FONT=Comic Sans MS][COLOR=navy]"Search Error!"[/COLOR][/FONT]
[FONT=Comic Sans MS][COLOR=navy]myEnd:[/COLOR][/FONT]
[FONT=Comic Sans MS][COLOR=navy]Application.ScreenUpdating = True[/COLOR][/FONT]
[FONT=Comic Sans MS][COLOR=navy]End Sub[/COLOR][/FONT]</o:p>
</o:p>
<o:p></o:p>
<o:p>Please help!!

Thanks!</o:p>
 
Last edited:

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.

tommyb

Board Regular
Joined
Aug 3, 2008
Messages
66
By the way, when I debug.. it points to the following line..

lngLstRow = Sheets("Sheet1").Cells(Rows.Count, 1).End(xlUp).Row

I have no idea why its wrong because it used to work!
 

Richard Schollar

MrExcel MVP
Joined
Apr 19, 2005
Messages
23,707
Hi

Try it like this:

Code:
With Sheets("Sheet1")
  lngLstRow = .Cells(.Rows.Count, 1).End(xlUp).Row
End With
 

tommyb

Board Regular
Joined
Aug 3, 2008
Messages
66
Doesnt work :(

Im really stumped on why it works on my desktop, but not when its ran through the intranet!
 

Richard Schollar

MrExcel MVP
Joined
Apr 19, 2005
Messages
23,707

ADVERTISEMENT

It fails on this line - ie it gets highlighted in yellow by the debugger?

lngLstRow = .Cells(.Rows.Count, 1).End(xlUp).Row

You did spot the addition of the period (in red) before the Rows?
 

tommyb

Board Regular
Joined
Aug 3, 2008
Messages
66
I have included the dot (I just pasted what you wrote on top of what I had. I debugged it again.. and now its highlighting this line yellow..

With Sheets("Sheet1")

It still works on my desktop, just not on the intranet!
 

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
36,916
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2010
Platform
  1. Windows
  2. MacOS

ADVERTISEMENT

Try fully qualifying everything - so for the line you mentioned you would want to use either Thisworkbook.Sheets("Sheet1") or Activeworkbook.Sheets("Sheet1")
 

Richard Schollar

MrExcel MVP
Joined
Apr 19, 2005
Messages
23,707
Does it help if you prefix the code with:

Rich (BB code):
With ThisWorkbook.Sheets("Sheet1")

amemdment is in red.
 

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
36,916
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2010
Platform
  1. Windows
  2. MacOS
Not the first time today. ;)
 

Watch MrExcel Video

Forum statistics

Threads
1,132,670
Messages
5,654,649
Members
418,146
Latest member
Shnn028

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
Top