Littleiitin
Below is what I use - I am just posting it as an alternative - I have no idea if one method is faster than the other.
The code below is what I use to read my default settings (settings selected by the user last time he ran the program) - so that is why the ColDefault has 2 added - so I actually read the last setting for the that variable into ReadValue.
I have all my messages in a module - so just rem out that call to message106
Thanks
Rasm
Code:
Public Sub ReadDefault(ValueToFind, ColDefault, RowDefault, ReadValue)
Dim RangeVal As String
Dim FoundCell As Range
Dim LastCell As Range
Dim LastRow As Long
Dim ColLast As Long
With ThisWorkbook.Worksheets("Default_Settings_01").UsedRange
LastRow = .Rows(.Rows.Count).Row
ColLast = .Columns(.Columns.Count).Column
End With
With ThisWorkbook.Worksheets("Default_Settings_01")
RangeVal = "A1:" & Split(Cells(1, ColLast).Address, "$")(1) & LastRow
With .Range(RangeVal)
Set LastCell = .Cells(.Cells.Count)
End With
Astr = ValueToFind
RangeVal = "A1:" & Split(Cells(1, ColLast).Address, "$")(1) & LastRow
With .Range(RangeVal)
Set LastCell = .Cells(.Cells.Count)
End With
Set FoundCell = .Range(RangeVal).Find(What:=(Astr), after:=LastCell)
If FoundCell Is Nothing Then
Astr = ValueToFind
Call Message106(Astr)
Else
ColDefault = FoundCell.Column + 2
RowDefault = FoundCell.Row
ReadValue = .Cells(FoundCell.Row, FoundCell.Column + 2)
End If
End With
End Sub
Bookmarks