Need to know why this fails

wut

Banned
Joined
Dec 13, 2010
Messages
229
Whenever I try to use "Range" as a method in this block of code, I get an error saying range method of object class failed. Those exact same methods work just fine when they're placed into any other macro.

Any suggestions?

(The two red lines are causing the failure... the ones that specify a "Range")

Rich (BB code):
sub test()
 
'==================================================
'Opens the browser and copies stuff
'==================================================
Dim Browser As Object
Set Browser = CreateObject("InternetExplorer.Application")
link = "http://www.google.com"
Browser.Navigate (link)
Browser.Visible = True
While Browser.Busy And Browser.ReadyState <> 4: DoEvents: Wend
Browser.ExecWB 17, 0
Browser.ExecWB 12, 0
Browser.Quit

'==================================================
'Pastes all website contents into worksheet
'Finds text, selects range to copy
'==================================================
 
ThisWorkbook.Sheets("Sheet1").Paste Destination:=Sheets("Sheet1").Range("A1")
For Each Cell In ActiveSheet.UsedRange
    If Cell.Value = "text" Then
        a = Cell.Offset(1, 0).Address
    End If
Next
ThisWorkbook.Sheets("Sheet1").Range(a, Range(a).SpecialCells(xlCellTypeLastCell)).Copy
ThisWorkbook.Sheets("Sheet1").Range("H1").PasteSpecial Paste:=xlPasteValuesAndNumberFormats
 
end sub
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Dryver: Any use of the Range method fails. I've tried it ten ways from Sunday.

leigao: Yeah, the cell I want to target using the variable "a" is getting targeted.

I just went back and tried the code I posted in the OP. It fails exactly the way I thought, so there's no mistake. Try commenting out the two red lines and you'll see exactly what I'm talking about.

This shouldn't be happening. What's going on...?
 
Upvote 0
This is totally ridiculous....

Just to make sure both halves of the code worked fine, I split the two halves into two macros. Not only do the two macros work independently, but the whole package works great when the first macro calls the second. The failure only occurs when the two halves are integrated into one procedure.

I'll post the tweaked code in a bit.
 
Upvote 0
I think I might need to do a web query to get around this problem. I've never done that before, so I don't even know where to start.
 
Upvote 0

Forum statistics

Threads
1,224,599
Messages
6,179,828
Members
452,946
Latest member
JoseDavid

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