Vba 如果某个工作表具有输入的日期,则尝试从该工作表复制行
我正在尝试将一个工作表中的行复制到另一个工作表中,如果它们有匹配的日期。我以前用过这种方法,效果很好。我一辈子都搞不清楚我到底哪里出了问题Vba 如果某个工作表具有输入的日期,则尝试从该工作表复制行,vba,excel,Vba,Excel,我正在尝试将一个工作表中的行复制到另一个工作表中,如果它们有匹配的日期。我以前用过这种方法,效果很好。我一辈子都搞不清楚我到底哪里出了问题 Public Sub dayreport() Dim enteredday As Variant Dim clockinday As Variant Dim y As Integer Dim yreport As Integer Dim yrow As Integer Dim daystring As Stri
Public Sub dayreport()
Dim enteredday As Variant
Dim clockinday As Variant
Dim y As Integer
Dim yreport As Integer
Dim yrow As Integer
Dim daystring As String
Dim datecheck As Boolean
'Collect the entered date
enteredday = CVar(Sheets("Process").Cells(3, 3)) 'get the datestring out of the date cell
'Only progress if a date is entered
If IsDate(enteredday) = True Then
datecheck = True 'a usable date has been entered
Else
datecheck = False
MsgBox "Entered date must be a real date of the format dd/mm/yyyy"
End If
If datecheck = True Then
'Delete the day report if it already exists
Call Delete_Sheet("Day Report")
'create a new sheet
Worksheets.Add.name = "Day Report"
y = 7
yreport = 7
yrow = 7
'While there is data in any of the cells of the investigated row, loop
Do While Sheets("Process").Cells(y, 1) <> "" _
Or Sheets("Process").Cells(y, 2) <> "" _
Or Sheets("Process").Cells(y, 3) <> "" _
Or Sheets("Process").Cells(y, 4) <> "" _
Or Sheets("Process").Cells(y, 5) <> "" _
Or Sheets("Process").Cells(y, 6) <> "" _
Or Sheets("Process").Cells(y, 7) <> "" _
Or Sheets("Process").Cells(y, 8) <> "" _
'breakdown entered date
year = CInt(Right(enteredday, 4)) 'take the year component from the date and convert it to an integer
month = CInt(Mid(enteredday, 4, 2)) 'take the month component from the date and convert it to an integer
day = CInt(Left(enteredday, 2)) 'take the day component from the date and convert it to an integer
enteredday = DateSerial(year, month, day)
'Breakdown investigated date
clockinday = CVar(Sheets("Process").Cells(y, 2)) 'get the datestring out of the date cell
sheetyear = CInt(Right(clockinday, 4))
sheetmonth = CInt(Mid(clockinday, 4, 2))
sheetday = CInt(Left(clockinday, 2))
clockinday = DateSerial(sheetyear, sheetmonth, sheetday)
'copy the row pairs into the day report sheet if the entered date matches the date in the row
If enteredday = clockinday Then
For i = 1 To 9
Sheets(“Day Report”).Cells(yreport, i) = Sheets(“Process”).Cells(y, i)
Sheets(“Day Report”).Cells(yreport + 1, i) = Sheets(“Process”).Cells(y + 1, i)
yreport = yreport + 2
Next i
End If
yrow = yrow + 2
y = y + 2
Loop
End If
End Sub
似乎它无法看到我的流程表,但它被另一个运行完美的子系统填充了为什么要将日期分解成碎片?为什么不直接寻找一个精确匹配的
mm/dd/yyyy
等?…或者将其转换为日期
并使用它呢?该日期将被分解,以便稍后划分信息,以便我可以直接调用月份等。我一直在努力让这对我来说更容易。您的行表(“日期报告”)中也使用了无效的引号.Cells(yreport,i)=工作表(“过程”).Cells(y,i)
和工作表(“日报告”).Cells(yreport+1,i)=工作表(“过程”).Cells(y+1,i)
-将其更改为正常“
。就是这样!引号!非常感谢。我不知道为什么我的键盘输入了这些引号,但我复制了你的,就是现在(buggily)复制的东西
Worksheets("Process").Range(CVar("A" & yrow & ":" & "I" & yrow + 1)).Copy Worksheets(“Day Report”).Range(CVar("A" & yreport & ":" & "I" & yreport + 1))