CellRead (SimpleLookup)

Simply reading a value from a specific cell from a sheet from a workbook (opened workbook)
The simple version of VLookup, works like Index or VLookup+Match
Index: Gets the value from cell giving row+Col
VLookup: Searches for a value in certain col, and/or searches for a header in certain row, then get the value of the intersection for that col, that row.
Can have sheet name and/or workbook name
any given combination can be used

CodeFunctionName
What is this?

Public

Tested

Original Work
Function CellRead( _
Optional ColumnName = "A", Optional RowNumber = 1, _
Optional Search4ID = "", Optional InColumnName = "A", _
Optional Search4Header = "", Optional InRowNumber = 1, _
Optional Shee = "This", Optional Wb = "This")
CellRead = SimpleLookup( ColumnName, RowNumber, Search4ID, InColumnName, Search4Header, InRowNumber, Shee, Wb)
End Function

Function SimpleLookup( _
Optional ColumnName = "A", Optional RowNumber = 1, _
Optional Search4ID = "", Optional InColumnName = "A", _
Optional Search4Header = "", Optional InRowNumber = 1, _
Optional Shee = "This", Optional Wb = "This")
'
' Gets value of cell of ColumnName and RowNumber
' If Search4ID is not blank, it will then search for that value in 'InColumnName' column
' If Search4Header is not blank, it will then search for that value in InRowNumber row
' Then return the value of the cell in that col, in that row
'
' If Search4ID is blank, RowNumber will be used
' If Search4Header is blank, ColumnName will be used
'
If Wb = "This" Then Wb = ThisWorkbook.Name
If Wb = "Active" Then Wb = ActiveWorkbook.Name
If Shee = "This" Then Shee = Workbooks(Wb).ActiveSheet.Name
SimpleLookup = ""
RowN = 0
ColN = 0
If Search4ID > "" And InColumnName > "" Then
Found1 = WorksheetFunction.CountIf(Workbooks(Wb).Worksheets(Shee).Range(InColumnName & 1).EntireColumn, Search4ID)
If Found1 = 0 Then Exit Function
If IsNumeric(Search4ID) Then RowID = Val(Search4ID)
RowN = WorksheetFunction.Match(Search4ID, Workbooks(Wb).Worksheets(Shee).Range(InColumnName & 1).EntireColumn, 0)
ElseIf RowNumber > 0 Then
RowN = RowNumber
End If
If Search4Header > "" And InRowNumber > 0 Then
Found1 = WorksheetFunction.CountIf(Workbooks(Wb).Worksheets(Shee).Range("A" & InRowNumber).EntireRow, Search4Header)
If Found1 = 0 Then Exit Function
ColN = WorksheetFunction.Match(Search4Header, Workbooks(Wb).Worksheets(Shee).Range("A" & InRowNumber).EntireRow, 0) - 1
ElseIf ColumnName > "" Then
ColN = Range(ColumnName & 1).Column - 1
End If
If RowN = 0 Or ColN = 0 Then Exit Function
SimpleLookup = Workbooks(Wb).Worksheets(Shee).Range("A" & RowN).Offset(, ColN).Value
End Function

Optional ColumnName, Optional RowNumber, Optional Search4ID, Optional InColumnName, Optional Search4Header, Optional InRowNumber, Optional Shee, Optional Wb

SimpleLookup("A", 3) ' Cell A3 in this workbook active sheet
SimpleLookup(, 14, , , "Date", 4) ' Row 14 + Column where we find Date in row 4

Views 3,048

Downloads 1,285

CodeID
DB ID