2
我的代碼如下顯示瞭如何根據列的值過濾某個範圍。每當我嘗試第二種情況和第三種情況時,我都會遇到運行時錯誤。運行時錯誤'1004'未找到單元格錯誤
嗨Jeeped,請查看以下編輯代碼:
Private Sub cmdATSend_Click()
'**************************************************************
'Copy Data
'**************************************************************
Dim myProject As String, sCriteria As String
myProject = InputBox("On what sheet do you wish to transfer these data?", "Daily Alarms Tracker", "ONO, INFINITY, or NET Brazil?")
With Sheets("Daily Alarms Tracker")
sCriteria = vbNullString
Select Case myProject
Case "INFINITY", "infinity", "Infinity", "inf", "Inf"
sCriteria = "INFINITY"
Case "ONO", "Ono", "ono"
sCriteria = "ONO"
Case "NET Brazil", "NET", "net brazil", "net", "Net Brazil", "NET BRAZIL"
sCriteria = "NET Brazil"
End Select
If CBool(Len(sCriteria)) Then
With .Range("C7:K18")
.AutoFilter
.AutoFilter Field:=1, Criteria1:=sCriteria
'.Offset(1, 0).Resize(.Rows.Count - 1, .Columns.Count).Select
If CBool(Application.Subtotal(103, .Offset(1, 0).Resize(.Rows.Count - 1, .Columns.Count))) Then
.Offset(1, 1).Resize(.Rows.Count - 1, .Columns.Count - 1).Copy
Else
Debug.Print "nothing matches"
End If
End With
End If
End With
'*******************************************************************
'Paste Data
'*******************************************************************
Dim atwb As Workbook
Set atwb = Workbooks.Open("https://ts.company.com/sites/folder1/folder2/01%20Project%20Documentations/Daily%20Alarms%20Tracker/Daily_Alarms_Tracker.xlsx")
Set atwb = ActiveWorkbook
Select Case sCriteria
Case "INFINITY"
Dim iRow As Long
With Sheets("INFINITY")
eRow = .Cells(Rows.Count, "B:B").End(xlUp).Row + 1
.Cells(iRow, "A").PasteSpecial xlPasteValuesAndNumberFormats
End With
Case "ONO"
Dim oRow As Long
With Sheets("ONO")
eRow = .Cells(Rows.Count, "B:B").End(xlUp).Row + 1
.Cells(oRow, "A").PasteSpecial xlPasteValuesAndNumberFormats
End With
Case "NET"
Dim nRow As Long
With Sheets("NET")
eRow = .Cells(Rows.Count, "B:B").End(xlUp).Row + 1
.Cells(nRow, "A").PasteSpecial xlPasteValuesAndNumberFormats
End With
End Select
End Sub
非常感謝!有用! :D – xtina1231
請問如何粘貼複製的單元格? – xtina1231
實際上,我更喜歡直接從單元格傳輸數據到單元格或'.Copy Destination:= ...'樣式傳輸。要粘貼你將不得不去活動工作表,這是要避免。如果您可以編輯原始問題以包含目標工作表和單元格(或位置說明,如列A中的第一個空單元格),那麼我將有一些工作。在不知道目的地的情況下,選擇最佳方法相當困難。 – Jeeped