Solved

Problems setting ranges

Posted on 2006-10-27
8
210 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
 
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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…

758 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now