Inspecting cells in a row in a named range

J

Jim

I have a large named range on my worksheet and want to have my code inspect
every cell in the first and last row only and NOT ispect every cell.

How can I modify my code to inspect the first row cell values?

Dim DataCell As Range
Dim FieldName As Name

For Each FieldName In ThisWorkBook.Names
If Not FieldName Is Nothing Then

For Each DataCell In Range(FieldName) 'Loops thru all names
Debug.Print "cell: ", DataCell.Cells.Value
Next DataCell

Endif
Next FieldName

thanks.
 
L

Leith Ross

Hello Jim,

This examines the first and last rows of data.


Code:
--------------------
Dim FirstRow As Long
Dim LastRow As Long
Dim FirstColumn As Long
Dim LastColumn As Long
Dim DataCell As Range
Dim FieldName As Name

For Each FieldName In ThisWorkBook.Names
If Not FieldName Is Nothing Then

Set DataCell = Range(FieldName)

With DataCell
FirstRow = .Row
LastRow = .Rows.Count - FirstRow + 1
FirstColumn = .Column
LastColumn = .Colummns.Count - FirstColumn + 1
End With

'Examine First Row of Data
For C = FirstColumn To LastColumn
Debug.Print "cell: ", DataCell.Cells(FirstRow, C).Value
Next C

'Examine Last Row of Data
For C = FirstColumn To LastColumn
Debug.Print "cell: ", DataCell.Cells(LastRow, C).Value
Next C

Endif

Next FieldName
 
J

Jim

Works great. (For anyone else using this, there is a trivial spelling error:
"Colummns." vice "Columns")

thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top