A
aherrera
Hello all,
I am working with two worksheets, and I need to use the formula COUNTIF
referencing another workbook. Unfortunately the name of the second
workbook changes so I have written a routine that asks the user to
point to that other workbook and thus save the path and file name.
However, when I try to enter the pathname as a variable in the formula,
I get an error. I have the following code (the problem is at the end of
info_processor() )
I appreciate any help.
Dim l As String
Dim pathname
Dim ThisSheet
Dim WKBookName
Public Sub main()
Call fileselect
Call info_processor
End Sub
Private Sub fileselect()
'get the current worksheet and workbook name
ThisSheet = ActiveWorkbook.ActiveSheet.Name
WKBookName = ThisWorkbook.Name
'*******set the inputList path*******
pathname = Application.GetOpenFilename("Excel files (*.xl*),*.xl*", _
1, "Select the input list", "select", False)
End Sub
Private Sub info_processor()
Set r = Workbooks(WKBookName).Worksheets(ThisSheet).Range("r6:aq6")
For Each cell In r
cell.FormulaR1C1 = _
"=COUNTIF([" & pathname & "]Offene!C6,""be"")"
Next cell
End Sub
![Frown :( :(](data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7)
I am working with two worksheets, and I need to use the formula COUNTIF
referencing another workbook. Unfortunately the name of the second
workbook changes so I have written a routine that asks the user to
point to that other workbook and thus save the path and file name.
However, when I try to enter the pathname as a variable in the formula,
I get an error. I have the following code (the problem is at the end of
info_processor() )
I appreciate any help.
Dim l As String
Dim pathname
Dim ThisSheet
Dim WKBookName
Public Sub main()
Call fileselect
Call info_processor
End Sub
Private Sub fileselect()
'get the current worksheet and workbook name
ThisSheet = ActiveWorkbook.ActiveSheet.Name
WKBookName = ThisWorkbook.Name
'*******set the inputList path*******
pathname = Application.GetOpenFilename("Excel files (*.xl*),*.xl*", _
1, "Select the input list", "select", False)
End Sub
Private Sub info_processor()
Set r = Workbooks(WKBookName).Worksheets(ThisSheet).Range("r6:aq6")
For Each cell In r
cell.FormulaR1C1 = _
"=COUNTIF([" & pathname & "]Offene!C6,""be"")"
Next cell
End Sub