Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / March 2008

Tip: Looking for answers? Try searching our database.

Selecting Ranges using Variables

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
DG - 20 Mar 2008 13:51 GMT
I currently have Sheet2 active in this example:

Sub TestIt()
   Dim Line as Integer

   Line = 8
   x = 1

   While Cells(x,1) <> ""
       Sheets("Sheet1").Range("A" & Line & ":K" & Line).Select
       x = x + 1
   Wend
End Sub

I get an error on the Select statement "Select Method of Range Class
Failed".

I am trying to select Range("ALine:KLine") where Line is the variable.

Any help would be great.

DG
BigJimmer - 20 Mar 2008 14:07 GMT
You need to have "Sheet1" active to select the range.  Try this...

Sub TestIt()
   Dim Line As Integer
   Dim x as Integer

   Line = 8
   x = 1

    Worksheets("Sheet1").Activate

   While Worksheets("Sheet2").Cells(x, 1) <> ""
       Worksheets("Sheet1").Range("A8:K8").Select
       x = x + 1
   Wend
End Sub

> I currently have Sheet2 active in this example:
>
[quoted text clipped - 18 lines]
>
> DG
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.