Looping: Selecting elements from a named range to change calcs
Udo.
Thanks for this: I'll study the syntax and adapt as necessary.
REgards
Phil
"Udo" wrote:
If your data are given in a consistent list (i.e. no empty lines
between them), then you could apply the following function:
Function LastRow _
(objSheet As Worksheet, _
strStartCell As String) As Range
Dim objRange As Range
Dim lngLastRow As Long
Dim lngLastCol As long
Set objRange = objSheet _
.Range(strStartCell).CurrentRegion
lngLastRow = objrange.Row + _
objRange.rows.count - 1
lngLastCol = objRange.Column + _
objRange.columns.Count - 1
With objSheet
Set Lastrow = .Range _
(.Cells(lngLastRow, objRange.Column), _
.Cells(lngLastRow, lngLastCol))
End with
End Function
You call the function from within your previous code by just entering
its name followed by the required information like
Rows = LastRow(Sheets("Variable List"), "C3").select
That would require, that you have that variable list copied into a
sheet within your active workbook named "Variable List". If this list
is in another workbook (assume it is ListFile.xls stored in c:\Temp),
the code would be something like:
Dim ListSource as Workbook
<main code here
set ListSource = workbooks.Open("c:\temp\ListFile.xls")
rows = LastRow(ListSource.Worksheets("Variable List"), "C3").select
Then, in the code we had established before, you would write:
For counter = 1 to Rows
......
With that you should be able to cope with your problem.
|