0
我是一個真正的VBA初學者,真實。可以使用UserForm中的VBA編碼來根據行和列內容查找單元格,然後更新該單元格?
我正在嘗試創建一個用戶表單,它將更新某個人在電子表格中列出的給定日期內完成的任務數量。我設想Userform有兩個botton(它們是隱藏的,並且作爲子例程的條件出現)。順便說一下,我正在Mac上工作,而且我知道在PC上使用VBA編碼會產生影響,反之亦然。
的示例片材是這樣的:
示例用戶窗體(a)是這樣的:
爲了便於討論,我們說我希望更新或輸入的Greg在5月7日完成的任務數量(2013/05/07)。
我想爲用戶窗體進行這樣的事情:
進入者和日期:
然後,點擊按鈕後第7檢索格雷格任務數:
現在,我想輸入我知道格雷格補全泰德7日6個任務,我單擊第二個按鈕(現在可見的第一個按鈕隱藏):在電子表格中
而結果:
我應該在這裏輸入一些代碼,但我的技能和代碼的完整性是想要的。但我會把我有什麼:
Option Explicit
'Subroutine when clicking the first ("find") button
Private Sub btnfind_Click()
lbltasks.Vissible = True
txttasks.Visible = True
btnupdate.Visible = True
btnfind.Visible = False
'Defining variables
Dim pr01 As String
Dim dt01 As Date
Dim tsk01 As Integer
'Assigning variables to inputs
pr01 = txtperson.Text
dt01 = txtdate.Text
tsk01 = txttask.Text
'Looking for Name in column "A"
' ? ? ?
'Looking for inut Date in row "1"
' ? ? ?
'Retrieving the existing number of tasks according to name and date
'and showing number in the 'tasks' text input box in the user form
' ? ? ?
End Sub
'Subroutine when clicking the Second ("update") button
Private Sub btnupdate_Click()
'Paste updated Number of tasks in appropriate cells according to name and date
'The new number of tasks should over write what was there previously
' ? ? ?
End Sub
在此先感謝您的任何和所有幫助!
Thanks @glh。但我仍然遇到問題。當我運行VBA /宏時,出現en錯誤:「運行時錯誤'91':對象變量或塊變量未設置。」當我點擊「調試」時,我來行:''尋找inut日期在行中「1」 With ThisWorkbook.Worksheets(「Sheet1」) frmDate = .Rows(1).Find(CDate(dt01))。Column End With# – 2013-05-06 13:55:20
我測試了這個好...這是3行。還要確保你正確設置了變量。有趣的是,它在上一行之後運行良好。 – glh 2013-05-06 18:27:15