2017-02-15 77 views
0

我在Col K中有一組日期「Latency」。我需要用戶輸入當前日期,然後代碼應該在輸入日期之前查找所有日期,複製整行並將其粘貼到名爲「Previous」的另一個表中。通過vba獲取用戶輸入

我一直堅持如何從用戶獲得輸入並將其集成到代碼中並執行上述操作。歡迎任何建議。

回答

1

你可以使用一個輸入框讓用戶輸入一個日期,檢查什麼實際上進入是一個日期,然後運行你想要的代碼:

Sub test() 
Dim userdate 

userdate = InputBox("Please enter a date", "Enter Date", Date) 
If IsDate(userdate) Then 
    'Do stuff here 
End If 

End Sub 
1

你可以嘗試像下面的代碼(增加了一些基本的錯誤處理)

Sub InputDateBox() 

Dim myDateString As String 
Dim myDate As Date 

myDateString = InputBox("Please enter a date", "Enter Date", Format(Date, "dd/mm/yyyy")) 

If IsDate(myDateString) Then 
    myDate = myDateString 
    'Do the rest of your coding here 
Else 
    MsgBox "Not a valid date format!" 
End If 

End Sub