Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Selecting working area in Excel 1

Status
Not open for further replies.

Stoffel24

Technical User
Apr 4, 2002
121
ZA
I have a spreadsheet with data that is sent through from another program. There is a top section of a set size and then underneath this with a blank line between there is another section that is of a variable size depending on how much data comes through.
ie

Top section
xxx x xxxx xxxx xxxx xx x xxxx xxx
xxx x xxxx xxxx xxxx xx x xxxx xxx
xxx x xxxx xxxx xxxx xx x xxxx xxx
Always 3 lines deep and 9 columns wide
Blank line
Bottom section
xxx xxxxx xx xxx xxx xxxx
xxx xxxxx xx xxx xxx xxxx
xxx xxxxx xx xxx xxx xxxx
xxx xxxxx xx xxx xxx xxxx
Variable no of lines deep, but set number of columns wide

What I would like to do is:
I have declared a variable...
Dim Rng As Range

I know the starting point of the range (B6). Then I want to populate Rng with the entire working area of the worksheet that is down and to the left of this starting point.
Next I want to run code that operates per column so can anyone tell me if there is something like
For all columns in Rng.

Many thanks


 
to answer the last part of your post, try something like:

Dim oRange As Range
Dim oColumn As Range
Dim oCell As Range

Set oRange = Selection

For Each oColumn In oRange.Columns
For Each oCell In oColumn.Cells
Debug.Print oCell.Address
Next oCell
Next oColumn
 
To get the full working area, it seems like you only need the number of rows but for a full solution:
lRow = ActiveSheet.UsedRange.Rows.Count
lcol = ActiveSheet.UsedRange.Columns.Count
For Each col In ActiveSheet.UsedRange.Columns
'Do Stuff Here
Next

HTH
~Geoff~
[noevil]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top