0
我很抱歉如果這是一個愚蠢的問題,但我一直無法找到我當前問題的答案。我正在嘗試創建一個用戶表單,它根據用戶名,開始日期和結束日期的組合框中的輸入來搜索電子表格數據。函數未在用戶表單子例程中正確定義
有一個用戶列和所有其他列對應於日期。數據是每日工作量生產力數量(例如87個小工具)。目標是能夠輸入輸入並將原始數據電子表格中的數據複製到結果電子表格中,以顯示該日期範圍內的一位用戶的信息。
我不斷收到一個錯誤(「編譯錯誤:子或未定義功能」)關於我嘗試使用該功能來定義適當的日期列。我會很感激任何輸入。謝謝。
'Function changes column number to column name
Public Function fnColumnToLetter_CellAdressReplace(ByVal ColumnNumber As Integer)
fnColumnToLetter_CellAdressReplace = Replace(Replace(Cells(1, ColumnNumber).Address, "1", ""), "$", "")
End Function
Private Sub SearchButton1_Click()
'Dim variables
Dim sheet As Worksheet
Dim name1 As String
Dim date1 As Date
Dim date2 As Date
Dim STARTcol As String
Dim ENDcol As String
Dim pharmcol1 As String
Dim pharmcol2 As String
Set sheet = ActiveWorkbook.Sheets("Data")
Set Results = ActiveWorkbook.Sheets("Results")
'Variables for entries input into userform
name1 = userform1.NameBox1.Value
date1 = userform1.DateBox1.Value
date2 = userform1.DateBox2.Value
'Define row based on pharmacist name
rowno = Application.WorksheetFunction.Match(name1, Range("A:A"), 0)
pharmrow = "a" + rowno
'Find first column from start date
STARTcol = Application.WorksheetFunction.Match(date1, Range("A1:AZZ1"), 0)
'Find last column from end date
ENDcol = Application.WorksheetFunction.Match(date2, Range("A1:AZZ1"), 0)
'Call function to replace column number to column name
pharmcol1 = fnColumnToLetter_CellAddressReplace(STARTcol) + rowno
pharmcol2 = fnColumnToLetter_CellAddressReplace(ENDcol) + rowno
'Copy table array to RESULTS worksheet
sheet.Range("pharmcol1:pharmcol2").Copy Destination = Results.Range("A1")
End Sub
發生錯誤時突出顯示哪行? –
嘗試'fnColumnToLetter_CellAddressReplace(STARTcol)&rowno'。和號是正確的字符串連接運算符。 – Jeeped
你有一個錯字'fnColumnToLetter_CellAddressReplace'應該是'fnColumnToLetter_CellAdressReplace'的功能只有一個'D'在'Adress' –