Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 33
Default used range between two cells...

Hi all,


I am trying to find the range(or may the used range) between two
cells. the situation is as below.

--------------
| First cell |
---------------
The first cell above spans only one colum. Everything that is below
this cell spans over multiple number of columns. The Last cell is also
spans only one column as below.

---------------
| Last Cell |
---------------

Now I am trying to get the used range between these two cells, given
that I have the address for the first cell and the last cell. Thanks in
advance for your help...

Shishi

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default used range between two cells...

Hi Shishi,

Depending on how you define the 'used range', try:

Sub TestIt()

Dim startCell As Range
Dim endCell As Range
Dim firstRow As Long
Dim lastCol As Long
Dim firstNewRow As Long, firstNewCol As Long
Dim lastNewRow As Long, lastNewCol As Long
Dim searchRng As Range
Dim MyUsedRng As Range

Set startCell = Range("C3") '<<======== CHANGE
Set endCell = Range("J21") '<<======== CHANGE

firstRow = startCell.Row + 1
lastCol = endCell.Column

Set searchRng = Range(Cells(firstRow, "A"), _
endCell.Offset(-1))


firstNewRow = searchRng.Find(what:="*", _
After:=searchRng(1), _
SearchOrder:=xlByRows, _
searchdirection:=xlNext).Row

firstNewCol = searchRng. _
Find(what:="*", _
After:=searchRng(1), _
SearchOrder:=xlByColumns, _
searchdirection:=xlNext).Column


lastNewRow = searchRng. _
Find(what:="*", _
After:=searchRng(1), _
SearchOrder:=xlByRows, _
searchdirection:=xlPrevious).Row

lastNewCol = searchRng. _
Find(what:="*", _
After:=searchRng(1), _
SearchOrder:=xlByColumns, _
searchdirection:=xlPrevious).Column

Set MyUsedRng = Range(Cells(firstNewRow, firstNewCol), _
Cells(lastNewRow, lastNewCol))

MyUsedRng.Select

MsgBox MyUsedRng.Address

End Sub

You can amend the definition of the 'used range' by changing the values for:

firstRow = startCell.Row + 1
lastCol = endCell.Column


---
Regards,
Norman



"shishi" wrote in message
oups.com...
Hi all,


I am trying to find the range(or may the used range) between two
cells. the situation is as below.

--------------
| First cell |
---------------
The first cell above spans only one colum. Everything that is below
this cell spans over multiple number of columns. The Last cell is also
spans only one column as below.

---------------
| Last Cell |
---------------

Now I am trying to get the used range between these two cells, given
that I have the address for the first cell and the last cell. Thanks in
advance for your help...

Shishi



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 33
Default used range between two cells...

Hi Norman,

Thanks for your reply..It works..

shishi

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
When entering data into a range of cells, select the entire range. Q Excel Discussion (Misc queries) 0 September 26th 07 04:36 AM
how to compute a range of cells based on another range of cells? HAROLD Excel Worksheet Functions 1 December 30th 05 09:32 PM
how to compute a range of cells based on another range of cells? HAROLD Excel Worksheet Functions 2 December 30th 05 07:55 PM
Count cells in one range based on parameters in another range dave roth Excel Worksheet Functions 2 March 29th 05 05:33 PM
Copy a formula to a range of cells via VB6 using .Range(Cells(row,col), Cells(row,col)).Formula= statement Kevin Excel Programming 7 October 5th 04 08:11 PM


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

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

About Us

"It's about Microsoft Excel"