Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > VBA / Office Integration > Excel > What is wrong with this?


Reply
 
Thread Tools Display Modes
  #1  
Old 06-20-2005, 02:12 AM
sirenko sirenko is offline
Regular
 
Join Date: Dec 2004
Location: Ankara, Turkey
Posts: 64
Default What is wrong with this?


Hi, I could not see why it gets error.
It gives "object" error at the point written in bold.

Code:
 With Workbooks("A.XLS").Worksheets("A")
         .Range("2:2").Insert
         .Range(Cells(2, 9), Cells(2, 11)).Value = .Range(Cells(3, 9), Cells(3, 11)).Value
         End With
Thanks...
Reply With Quote
  #2  
Old 06-20-2005, 03:18 AM
italkid's Avatar
italkid italkid is offline
Down...

Retired Moderator
* Expert *
 
Join Date: Dec 2002
Location: Belgium.
Posts: 6,731
Default

You refer to "Cells" from which workbook/sheet...

So, in your code "Cells(2, 11)).Value" for instance will refer to the active sheet, no matter which one it is. If you don't want that to happen you'll have to put a dot in front of it:
Code:
With Workbooks("A.XLS").Worksheets("A") .Range("2:2").Insert .Range(.Cells(2, 9), .Cells(2, 11)).Value = .Range(.Cells(3, 9), .Cells(3, 11)).Value End With
Reply With Quote
  #3  
Old 06-20-2005, 09:53 AM
NateO's Avatar
NateO NateO is offline
Excellent…

Forum Leader
* Expert *
 
Join Date: Jun 2004
Location: Minneapolis MN - deceased
Posts: 2,483
Default

Try the following:

Code:
Range(.Cells(2, 9), .Cells(2, 11)).Value = Range(.Cells(3, 9), .Cells(3, 11)).Value
Qualify the ranges passed in the Range reference, but not the outer Range, it knows what to do from there.
__________________
Regards,
Nate Oliver
Microsoft Excel MVP
Reply With Quote
  #4  
Old 06-20-2005, 04:44 PM
sirenko sirenko is offline
Regular
 
Join Date: Dec 2004
Location: Ankara, Turkey
Posts: 64
Default

Thank you for all worthy replies.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->