I am trying to find the a row and column number to paste data in that cell. The rows are the various metrics to look for, the columns the dates. I prefer to use a function for it, so I can simply call the function an pass the different parameter.
It is the reverse from this thread: How to find cell value based on row and Column ID in excel VBA. I want to find the address of a cell.
The code I have so far:
Sub FindMyCell()
Dim myDate As String
Dim myMetric As String
Dim foundRange As Range
Dim pasteRange As Range
Dim r As Range, c As Range
Worksheets("Sheet1").Range("B20").Select
myDate = Worksheets("Sheet1").Range("B20").Value
myMetric = Worksheets("Sheet1").Range("B21").Value
FindCell(myMetric,myDate)
Inputcell = foundRange.Address
End Sub
Function FindCell(myMetric As String, myDate As String) As String
With ActiveCell
r = .Columns("B").Find(myMetric).row
c = .Rows("3").Find(myDate).Column
If r = Nothing Or c = Nothing Then
'errorcount = errorcount + 1
'Exit Function
End If
Set pasteRange = .Cells(r, c).Address
End With
End Function
I keep getting: Compile error: Argument not optional in the line:
Set foundRange = FindCell(myDate & myMetric)