Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 138
Default How do I pass a variable cell reference to a Range Object?

I will be choosing the end of data point (over and over) and then offsetting
the active cell by some value. I don't know how to reference that new active
cell so that I can tell another function that that is its destination.

'goes to last cell in data set (Ex: A10)
ActiveCell.SpecialCells(xlLastCell).Select

'active cell 1 down and 9 left (Ex: B1)
ActiveCell.Offset(1, -9).Range("A1").Select

'How do I indicate that Destination is B1, when B1 Changes each time?
Instead of
'"$A$85" I want to give it a relative variable.
Destination:=Range("$A$85"))


NOTE: I thought I could put in something like

Destination:=Range("ActiveCell.SpecialCells(xlLast Cell).Select_
ActiveCell.Offset(1, -9).Range("A1").Select" ))
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,355
Default How do I pass a variable cell reference to a Range Object?

I'm not sure what you're doing with destination, but you could do something
like this

Sub test1()
Dim aWS As Worksheet
Dim myRange As Range
'goes to last cell in data set (Ex: A10)
Set aWS = ActiveSheet

Set myRange = ActiveCell.SpecialCells(xlLastCell)

'active cell 1 down and 9 left (Ex: B1)
Set myRange = Nothing
On Error Resume Next
Set myRange = myRange.Offset(1, -9)
On Error GoTo 0

If Not myRange Is Nothing Then
'Destination:= myRange 'I'm sure there's more to this
End If

End Sub
--
HTH,
Barb Reinhardt

If this post was helpful to you, please click YES below.



"Paula" wrote:

I will be choosing the end of data point (over and over) and then offsetting
the active cell by some value. I don't know how to reference that new active
cell so that I can tell another function that that is its destination.

'goes to last cell in data set (Ex: A10)
ActiveCell.SpecialCells(xlLastCell).Select

'active cell 1 down and 9 left (Ex: B1)
ActiveCell.Offset(1, -9).Range("A1").Select

'How do I indicate that Destination is B1, when B1 Changes each time?
Instead of
'"$A$85" I want to give it a relative variable.
Destination:=Range("$A$85"))


NOTE: I thought I could put in something like

Destination:=Range("ActiveCell.SpecialCells(xlLast Cell).Select_
ActiveCell.Offset(1, -9).Range("A1").Select" ))

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default How do I pass a variable cell reference to a Range Object?

These two topics are in the VBA help files and will
provide sample code to illustrate how the references work.
You might also want to look at the Offset property and
the example code for that. There are several ways that you
can apply cell references by variables, offset and relative
reference.

1. Referring to Cells Relative to Other Cells
2. How to Reference Cells and Ranges

"Paula" wrote:

I will be choosing the end of data point (over and over) and then offsetting
the active cell by some value. I don't know how to reference that new active
cell so that I can tell another function that that is its destination.

'goes to last cell in data set (Ex: A10)
ActiveCell.SpecialCells(xlLastCell).Select

'active cell 1 down and 9 left (Ex: B1)
ActiveCell.Offset(1, -9).Range("A1").Select

'How do I indicate that Destination is B1, when B1 Changes each time?
Instead of
'"$A$85" I want to give it a relative variable.
Destination:=Range("$A$85"))


NOTE: I thought I could put in something like

Destination:=Range("ActiveCell.SpecialCells(xlLast Cell).Select_
ActiveCell.Offset(1, -9).Range("A1").Select" ))

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Variable Cell Range Reference Ken Excel Worksheet Functions 3 August 12th 07 07:35 PM
VLOOKUP variable range cell reference Ohp Excel Worksheet Functions 2 July 3rd 07 02:52 PM
Pass a range object as a parameter clara Excel Programming 5 April 27th 07 05:34 AM
Pass a variable into a range? Ian Fleming[_2_] Excel Programming 1 September 7th 05 09:45 AM
How to (re)set a range.value to pass -0- to a "double" variable Dennis Excel Discussion (Misc queries) 2 April 15th 05 11:13 AM


All times are GMT +1. The time now is 03:34 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"