Solved

Problems setting ranges

Posted on 2006-10-27
8
212 Views
Last Modified: 2010-04-30
This is the beginning of my macro, and it keeps on giving me errors.  I am trying to scroll down column N until the two cells to the right are blank.  I cannot figure out why this isn't working....

Sub Range()
Dim r As Range
Set r = Range("N1").Select

Do Until r.Offset(0, 1).value = "" And r.Offset(0, 2).value = ""
Set r = r.Offset(1, 0)
Loop
Set r = r.Offset(1, 0)

End Sub
0
Comment
Question by:tiehaze
  • 5
  • 2
8 Comments
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 17822166
>nd it keeps on giving me errors
what errors?
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 17822169
note that I would change the Sub name from RANGE to something else, like SetRange for example...
0
 

Author Comment

by:tiehaze
ID: 17822201
'object required' ===> Set r = Range("N1").Select
0
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 17822282
Range is an Excel KEYWORD, and you will encounter all kinds of problems by using that as the name of a Proceude in Excel.

make this change:

Sub My_Range()
Dim r As Range
Set r = Range("N1").Select

Do Until r.Offset(0, 1).value = "" And r.Offset(0, 2).value = ""
Set r = r.Offset(1, 0)
Loop
Set r = r.Offset(1, 0)

End Sub

AW
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 17822296
So I confirm my suggestion of changing the procedure name (same what Arthur_Wood suggests)
angelIII
0
 

Author Comment

by:tiehaze
ID: 17822322
Doesn't change anything... I am still getting the error. If it helps, it is a run time error 424
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 17822344
you might want to specify the worksheet you want to handle, for example sheet1.range instead of simply raying range


Sub SetRange()
Dim r As Range
Set r = sheet1.Range("N1").Select

Do Until r.Offset(0, 1).value = "" And r.Offset(0, 2).value = ""
Set r = r.Offset(1, 0)
Loop
Set r = r.Offset(1, 0)

End Sub
0
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 17822345
also, you don't need the .select:


Sub SetRange()
Dim r As Range
Set r = sheet1.Range("N1")

Do Until r.Offset(0, 1).value = "" And r.Offset(0, 2).value = ""
Set r = r.Offset(1, 0)
Loop
Set r = r.Offset(1, 0)

End Sub
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question