셀 d2 = Qtr 1 (Qtr 2 일 수도 있고 j = 1, 2 또는 3. 그러나 내 코드를 내게 오류 대신 날짜, 셀 문자열이 있습니다. 셀이 비어 있으면 행을 건너려고 가져옵니다 있지만 셀에 문자열 ("시작 날짜 입력 . ") 다음 코드가 중지되고 디버거가 열립니다 어떻게 내가 셀에 문자열이있는 경우 건너 뛸 내 코드를 요청할 수 있습니다 내가 조건부 추가 시도VBA를 사용하여 문자열을 포함하는 루프의 셀을 건너 뛸 수있는 방법
: 조건부
if cells(2,4) = "Qtr 1" And Month(cells(i,10)) = 2 And cells(i,10) <> "[Enter Start Date]" then
불행하게도을 <> "[En ter Start Date] "가 작동하지 않습니다 ... 시도했습니다.
if cells(2,4) = "Qtr 1" And Month(cells(i,10)) = 2 Andcells(i,10).numberFormat = "m/d/yyyy" then
이 방법은 작동하지 않습니다.
아이디어가 있으십니까? 내 코드는 아래에 있으며 반복되는 이미지의 예가 이미지에서 볼 수 있습니다.
Sub copyQtr()
Dim i As Long
Dim j As Long
Dim sheetName As String
Dim LastCol As Integer
Dim LastRow As Integer
Sheets("Activities").Activate
LastRow = Cells(Rows.Count, 10).End(xlUp).Row
LastCol = Cells(10, Columns.Count).End(xlToLeft).Column
sheetName = Sheets("Activities").Cells(2, 4)
Cells(4, 1) = sheetName
j = 11
For i = 11 To LastRow
If Cells(2, 4) = "Qtr 1" And Month(Cells(i, 10)) = 1 Then
Sheets("Activities").Range(Cells(i, 2), Cells(i, 12)).Copy
Sheets(sheetName).Cells(j, 2).PasteSpecial
j = j + 1
ElseIf Cells(2, 4) = "Qtr 1" And Month(Cells(i, 10)) = 2 Then
Sheets("Activities").Range(Cells(i, 2), Cells(i, 12)).Copy
Sheets(sheetName).Cells(j, 2).PasteSpecial
j = j + 1
ElseIf Cells(2, 4) = "Qtr 1" And Month(Cells(i, 10)) = 3 Then
Sheets("Activities").Range(Cells(i, 2), Cells(i, 12)).Copy
Sheets(sheetName).Cells(j, 2).PasteSpecial
j = j + 1
ElseIf Cells(2, 4) = "Qtr 2" And Month(Cells(i, 10)) = 4 Then
Sheets("Activities").Range(Cells(i, 2), Cells(i, 12)).Copy
Sheets(sheetName).Cells(j, 2).PasteSpecial
j = j + 1
ElseIf Cells(2, 4) = "Qtr 2" And Month(Cells(i, 10)) = 5 Then
Sheets("Activities").Range(Cells(i, 2), Cells(i, 12)).Copy
Sheets(sheetName).Cells(j, 2).PasteSpecial
j = j + 1
ElseIf Cells(2, 4) = "Qtr 2" And Month(Cells(i, 10)) = 6 Then
Sheets("Activities").Range(Cells(i, 2), Cells(i, 12)).Copy
Sheets(sheetName).Cells(j, 2).PasteSpecial
j = j + 1
ElseIf Cells(2, 4) = "Qtr 3" And Month(Cells(i, 10)) = 7 Then
Sheets("Activities").Range(Cells(i, 2), Cells(i, 12)).Copy
Sheets(sheetName).Cells(j, 2).PasteSpecial
j = j + 1
ElseIf Cells(2, 4) = "Qtr 3" And Month(Cells(i, 10)) = 8 Then
Sheets("Activities").Range(Cells(i, 2), Cells(i, 12)).Copy
Sheets(sheetName).Cells(j, 2).PasteSpecial
j = j + 1
ElseIf Cells(2, 4) = "Qtr 3" And Month(Cells(i, 10)) = 9 Then
Sheets("Activities").Range(Cells(i, 2), Cells(i, 12)).Copy
Sheets(sheetName).Cells(j, 2).PasteSpecial
j = j + 1
ElseIf Cells(2, 4) = "Qtr 4" And Month(Cells(i, 10)) = 10 Then
Sheets("Activities").Range(Cells(i, 2), Cells(i, 12)).Copy
Sheets(sheetName).Cells(j, 2).PasteSpecial
j = j + 1
ElseIf Cells(2, 4) = "Qtr 4" And Month(Cells(i, 10)) = 11 Then
Sheets("Activities").Range(Cells(i, 2), Cells(i, 12)).Copy
Sheets(sheetName).Cells(j, 2).PasteSpecial
j = j + 1
ElseIf Cells(2, 4) = "Qtr 4" And Month(Cells(i, 10)) = 12 And Cells(i, 10).NumberFormat = "m/d/yyyy" Then
Sheets("Activities").Range(Cells(i, 2), Cells(i, 12)).Copy
Sheets(sheetName).Cells(j, 2).PasteSpecial
j = j + 1
End If
Next
End Sub
경우 세포 (I, 10) 셀이 포함 된 경우
isDate() 함수를 사용해 보셨습니까? http://www.techonthenet.com/excel/formulas/isdate.php – Alex
그냥 해냈다. 고맙습니다! –