Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Create a new range from existing range

Hi,

I am writing a user defined function with a range as one of the
arguments e.g. N4:N14. While executing the function, I need to find
out cells in column x units away e.g. when x = 1 output should be
O4:14 or when x =2 output should P4:P14. I need to assign new range to
a variable of type range.

I am new to VBA. Can you help me?

Sachchi
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default Create a new range from existing range

Sounds like you are looking for Offset

Sub test()
Dim sAddr as string
Dim rng As Range
Dim nOffRows As Long, nOffCols As Long

Set rng = Range("A1:A10")

nOffRows = 0
nOffCols = 2
sAddr = rng.Offset(nOffRows, nOffCols).Address(0, 0)

MsgBox sAddr

End Sub

Keep in mind if the Offset tries to take the range off the sheet it will
error.

Regards,
Peter T


"Sachchi" wrote in message
...
Hi,

I am writing a user defined function with a range as one of the
arguments e.g. N4:N14. While executing the function, I need to find
out cells in column x units away e.g. when x = 1 output should be
O4:14 or when x =2 output should P4:P14. I need to assign new range to
a variable of type range.

I am new to VBA. Can you help me?

Sachchi



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
How do I add an apostrophy to a range of existing cells? stuck Excel Worksheet Functions 3 August 20th 09 02:07 AM
Delete Rows based on not existing in range [email protected] Excel Programming 3 June 29th 07 02:16 PM
Create/copy combo boxes in one range if condition is met in a different range LB[_4_] Excel Programming 4 September 30th 05 12:21 AM
Add a Range to an existing Range in a loop? Mick Excel Programming 3 June 18th 05 06:12 AM
Open only existing Excel Files in a given Range Matty C[_2_] Excel Programming 1 October 5th 04 01:32 PM


All times are GMT +1. The time now is 02:31 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"