Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ Finds queried value in a specified row and returns the column number where the q
**Input**:
1. `Worksheet` Search Worksheet _(ex. ThisWorkbook.Sheets("Sheet 1"))_
2. `String` Search Term _(ex. "foo")_
3. `String` Search Row _(ex. "1:1")_
3. `Range` Search Row _(ex. Range("1:1"))_

**Output**: `Integer` Column Number

Expand Down
12 changes: 6 additions & 6 deletions findQueryInRow.bas
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@
'''''''''''''''''''''''''''''''''''''''''''''''
' *** Requires Function "getColumnLetter" ***

'receives input of worksheet (ex. ThisWorkbook.Sheets("Sheet 1")), search term (ex. "foo"), and range (ex. "1:1") as string
'receives input of worksheet (ex. ThisWorkbook.Sheets("Sheet 1")), search term (ex. "foo"), and range (ex. Range("1:1")) as Range
'outputs column number as integer

Function findQueryInRow(searchWorksheet As Worksheet, searchTerm As Variant, searchRow As String) As Integer
Function findQueryInRow(searchWorksheet As Worksheet, searchTerm As Variant, searchRow As Range) As Integer

'''method 1
'dimension variables
Dim ws As Worksheet: Set ws = searchWorksheet
Dim foundCol As Integer

'find the search term within the search range
Dim foundSearchTerm As range: Set foundSearchTerm = ws.range(searchRow).Find(what:=searchTerm, LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows, MatchCase:=False)
Dim foundSearchTerm As range: Set foundSearchTerm = searchRow.Find(what:=searchTerm, LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows, MatchCase:=False)
Comment on lines 16 to +17

'if search term is found return row number
'else try method 2
Expand All @@ -29,15 +29,15 @@ Function findQueryInRow(searchWorksheet As Worksheet, searchTerm As Variant, sea
'dimension variables

'find the column letter of the last column in the search row
Dim searchRowLastColumnLetter As String: searchRowLastColumnLetter = common.getColumnLetter(ws.range(common.getColumnLetter(Columns.count) & ws.range(searchRow).row).End(xlToLeft).Column)
Dim searchRowLastColumnLetter As String: searchRowLastColumnLetter = common.getColumnLetter(ws.range(common.getColumnLetter(Columns.count) & searchRow.row).End(xlToLeft).Column)
Comment on lines 31 to +32

'find the last row in the search search row
Dim searchRowLastRow As String: searchRowLastRow = ws.range(searchRow).row
Dim searchRowLastRow As String: searchRowLastRow = searchRow.row

'find the last cell in the search row
Dim searchRowLastCell As range: Set searchRowLastCell = ws.range(searchRowLastColumnLetter & searchRowLastRow)

Dim row As Integer: row = ws.range(searchRow).row
Dim row As Integer: row = searchRow.row
Dim i As Long
Dim foundMatch As Boolean: foundMatch = False
Dim compare As String
Expand Down