ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Build a range from a cell (https://www.excelbanter.com/excel-programming/387332-build-range-cell.html)

[email protected]

Build a range from a cell
 
I am using the OWC and i need to build a range from another range
using a starting cell.

So i have
src.address = "A23:AA24"
dest.address = "A27"

I need to calculate the end of the range based on the dest.address
cell.
the end result would be

dest.address = "A27:AA28"

I need to do this wil Excel vba... any ideas?

thanks
TT


Barb Reinhardt

Build a range from a cell
 
Try this:

Dim src As Range
Dim dest As Range

Set src = Range("A23:AA24")
Set dest = Range("A27")

Set dest = src.Offset(dest.Row - src.Row, dest.Column - src.Column)





" wrote:

I am using the OWC and i need to build a range from another range
using a starting cell.

So i have
src.address = "A23:AA24"
dest.address = "A27"

I need to calculate the end of the range based on the dest.address
cell.
the end result would be

dest.address = "A27:AA28"

I need to do this wil Excel vba... any ideas?

thanks
TT



Peter T

Build a range from a cell
 
Set src = Range("A23:AA24")
Set dest = Range("A27")

With src
Set dest = dest.Resize(.Rows.Count, .Columns.Count)
End With

Debug.Print dest.Address ' $A$27:$AA$28

Before resizing you might also want to ensure the new range does would not
extend off the sheet.

Regards,
Peter T

wrote in message
ps.com...
I am using the OWC and i need to build a range from another range
using a starting cell.

So i have
src.address = "A23:AA24"
dest.address = "A27"

I need to calculate the end of the range based on the dest.address
cell.
the end result would be

dest.address = "A27:AA28"

I need to do this wil Excel vba... any ideas?

thanks
TT




Jim Thomlinson

Build a range from a cell
 
Give this a whirl...

Sub test()
Dim src As Range
Dim dest As Range

Set src = Range("A23:AA24")
Set dest = Range("A27").Resize(src.Rows.Count, src.Columns.Count)
MsgBox dest.Address
End Sub
--
HTH...

Jim Thomlinson


" wrote:

I am using the OWC and i need to build a range from another range
using a starting cell.

So i have
src.address = "A23:AA24"
dest.address = "A27"

I need to calculate the end of the range based on the dest.address
cell.
the end result would be

dest.address = "A27:AA28"

I need to do this wil Excel vba... any ideas?

thanks
TT




All times are GMT +1. The time now is 02:53 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com