Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel Macro - Method 'Range' of object '_Global' failed 1

Status
Not open for further replies.

hazelsisson

Programmer
Mar 18, 2002
68
0
0
GB
Hi guys,

I have a problem with some code I've written which takes some data from Sheet 1 of my workbook and pastes it into Sheet 2.

The error occurs on the line "Range(Bcell).Copy". When I debug I can see that Bcell is holding the value of the cell; I'm not sure if it should be this or the address to the cell.

Code:
Sub wholeRow()

   For Each Bcell In Range("Sheet1!C3:Sheet1!C36")
    
    Sheets("Sheet1").Select
    Range(Bcell).Copy
    Sheets("Sheet2").Select
    ...(etc)...

Next Bcell
        
End Sub

The sheet is open and active when I run the macro.

Any help would be wonderful.

Thanks,
Hazel
 
For future reference, pleas epost VBA questions in the VBA forum (Forum707)

In this instance, I believe the reason you are getting an error is that Range() requires a STRING to be passed to it.

BCell is in fact a RANGE

this is where explicitly declaring variables helps

try this:
Code:
Sub wholeRow()
[b]dim BCell as range[/b]
   For Each Bcell In sheets("Sheet1").Range("C3:C36")
    Bcell.Copy destination:= Sheets("Sheet2").Range("Where you want tot Paste")
    ...etc etc...
   Next


Rgds, Geoff

We could learn a lot from crayons. Some are sharp, some are pretty and some are dull. Some have weird names and all are different colours but they all live in the same box.

Please read FAQ222-2244 before you ask a question
 
Excellent, that worked!

Also the Bcell.Copy method was a lot more efficient than what I was using.

Thanks very much.
Hazel
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top