Solved

Problems setting ranges

Posted on 2006-10-27
8
214 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
8 Comments
 
LVL 143

Expert Comment

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

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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
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 143

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 143

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 143

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Paint/Redraw window while dragging 16 88
Adding to a VBA? 6 85
How to set the sa password in a vb6 code for sql connection 9 63
VBA Shell can't Find Word document 11 131
There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

726 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