我一直在研究以下代码,以自动从一张纸张到另一张纸张进行数据传输;但是我仍然坚持如何编写时间元素。时间将采用hh:mm格式,并以相同的格式传输。任何帮助将不胜感激!!
Private Sub Commandbutton1_Click()
Dim Dateadded As Date
Dim Time As ???
Dim nameoftask As String
Dim typeoftask As String
Dim Iffollowupwhichtaskisitfollowing As String
Dim Howwastaskcommunicated As String
Dim Whowastaskcommunicatedto As String
Dim Whorequestedtask As String
Dim Whatistaskrequiredfor As String
Dim Descriptionoftask As String
Dim Deadlinefortask As Date
Dim myData As Workbook
Worksheets("sheet1").Select
Dateadded = Range("b5")
Time = Range("b7")
nameoftask = Range("b9")
typeoftask = Range("b11")
Iffollowupwhichtaskisitfollowing = Range("b13")
Howwastaskcommunicated = Range("b15")
Whorequestedtask = Range("b17")
Whatistaskrequiredfor = Range("b19")
Descriptionoftask = Range("b21")
Deadlinefortask = Range("b23")
Set myData = Workbooks.Open("filelink")
Worksheets("sheet1").Select
Worksheets("sheet1").Range("a1").Select
RowCount = Worksheets("sheet1").Range("a1").CurrentRegion.Rows.Count
With Worksheets("sheet1").Range("a1")
.Offset(RowCount, 1) = Date
.Offset(RowCount, 2) = Time
.Offset(RowCount, 3) = nameoftask
.Offset(RowCount, 4) = typeoftask
.Offset(RowCount, 5) = Iffollowupwhichtaskisitfollowing
.Offset(RowCount, 6) = Howwastaskcommunicated
.Offset(RowCount, 7) = Whowastaskcommunicatedto
.Offset(RowCount, 8) = Whorequestedtask
.Offset(RowCount, 9) = Whatistaskrequiredfor
.Offset(RowCount, 10) = Descriptionoftask
.Offset(RowCount, 11) = Deadlinefortask
End With
myData.Save
End Sub
答案 0 :(得分:0)
如果将时间变量调暗为日期,则单元格格式将与您的方法相对应。
如果时间存储并在单元格中显示为时间值,则其基础数据类型是小于1的十进制数。因此您也可以将其调暗为双精度数。
如果在当前代码中使用double,则格式不会出现在新单元格中,只是单元格值。您需要使用首选时间格式格式化目标单元格。
因此,Date是您想要调暗的数据类型。