求救.我用錄製巨集.把sheet1 的A欄到F欄最底下248筆資料 copy放到Sheet2 , 但由於資料數量每次都會變.可能變多.也可能變少.導致每次都抓不到我要的最底下248筆資料.有大大可以幫忙嗎?

2018-02-08 11:13 pm

回答 (2)

2018-02-09 8:00 am
✔ 最佳答案
Sub Macro1()
Sheets("Sheet1").Select
SelectDataAndCopy (248)
Sheets("Sheet2").Select
Range("A4").Select
ActiveSheet.Paste
End Sub

Public Sub SelectDataAndCopy(ByVal numberOfRow As Integer)
Dim sht As Worksheet
Dim startAtRow As Integer
Dim endAtRow As Integer
Sheets("Sheet1").Select
Set sht = ActiveSheet
endAtRow = sht.Cells(sht.Rows.Count, "A").End(xlUp).Row
startAtRow = endAtRow - numberOfRow + 1
Range("a" & startAtRow & ":f" & endAtRow).Select
Selection.Copy
End Sub
2018-02-09 12:47 pm
With Sheets("Sheet1")
Cx = .[A1048576].End(3).Row
Cxa = Cx - 247
.Range("A" & Cxa & ":F" & Cx).Copy Sheets("Sheet2").Range("A4")
End With


收錄日期: 2021-05-03 06:48:10
原文連結 [永久失效]:
https://hk.answers.yahoo.com/question/index?qid=20180208151346AABQiav

檢視 Wayback Machine 備份