Sub match2()
'combine id card no and date for searching
Dim srcrange As Range, fndrange As Range
Dim fstaddress As String, i As Integer
Dim fc As Integer
Dim fr As Integer
Dim fr2 As Integer
Worksheets("attendance report").Activate
fc = 1
fr = 4
fr2 = 3
Set srcrange = Worksheets("data").Range("a4").CurrentRegion.Columns(9)
Set fndrange = srcrange.Find(what:=Cells(fr, fc) & Format(Cells(fr2, 11), "d/m/yyyy"))
If Not fndrange Is Nothing Then
fstaddress = fndrange.Address
i = 5
Do
Cells(i, 11).Value = fndrange.Offset(, -2).Value
Cells(i + 1, 11).Value = fndrange.Offset(3, -2).Value
Cells(i + 7, 11).Value = fndrange.Offset(2, -2).Value
Cells(i + 8, 11).Value = fndrange.Offset(1, -2).Value
i = 1 + 1
Loop Until fndrange.Address = fstaddress
Else
MsgBox "XX"
End If
End Sub作者: missbb 時間: 2015-8-15 20:14
Selection.Copy次<<這裡裡是選擇上面範圍A4:AP23製範圍的複製
但下面的紅色部份卻把上面的選擇更換掉了,所以它只能貼一次,第二次就會出錯了!
For i = 1 To QQQQ
ActiveSheet.Range("A" & 1 + i * 20).Select
ActiveSheet.Paste
Next i
要複製貼上,只要一句就可解決,如下範例: