試試這個:
Private Sub CommandButton1_Click()
If Sheets("MRT").Range("L8").Value like "*X*" Then
Sheets("MRT").Range("E42:AA42").Copy
Sheets("Test '12").Cells(3, 1).PasteSpecial Paste:=xlValues, Operation:=xlNone
End If
End Sub
在我的測試工作過,但是你可能要適應Cells(3,1)
和其他位置說明符到您想要的目標。
編輯:忘了用幾個月零件...等一下...點擊這裏:從here
Sub FindSignificant()
Dim SearchString As String
Dim SearchRange As Range, cl As Range
Dim FirstFound As String
Dim sh As Worksheet
' Set Search value
SearchString = "a"
Application.FindFormat.Clear
' loop through all sheets
Set sh = Sheets("MRT")
' Find first instance on sheet
Set cl = sh.Cells.Find(What:=SearchString, _
After:=sh.Cells(1, 1), _
LookIn:=xlFormulas, _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False, _
SearchFormat:=False)
If Not cl Is Nothing Then
' if found, remember location
FirstFound = cl.Address
' format found cell
Do
Select Case sh.Cells(cl.Row, 1).Value
Case "december"
sh.Range("E42:AA42").Copy
Sheets("Test '12").Cells(3, 1).PasteSpecial Paste:=xlValues, Operation:=xlNone
Case "february"
sh.Range("E42:AA42").Copy
Sheets("Test '12").Cells(3, 1).PasteSpecial Paste:=xlValues, Operation:=xlNone
Case Else
'do nothing
End Select
' find next instance
Set cl = sh.Cells.FindNext(After:=cl)
' repeat until back where we started
Loop Until FirstFound = cl.Address
End If
End Sub
這段代碼起源你必須適應選擇的情況下,但如果沒有必要,我真的會考慮解決這個問題;)
你可以更具體的具體細胞?如果一月是'L8',二月是什麼?如果要在「L8」上覆制的範圍是「E42:AA42」,那麼二月份是什麼?目標表名稱和位置等應遵循哪些規則? – brettdj
這聽起來很像VLOOKUP,但是每個複製目標單元都必須使用它,並且不會有按鈕。 – Jook