Excel VBA

2014-11-25 1:25 am
Dear Friends,

Would you like to solve the VBA of excel problem stated below for me. Many thnks!

I have import about thousands row of records (different import with different row of records) in a worksheet of an excel file. I want to select different records (e.g. record containing "1" in column A) from the worksheet and then copy them to a new worksheet of the same excel file and then "2" in column A and so on. Thanks!


Best Regards

回答 (2)

2014-11-25 3:14 am
✔ 最佳答案
Assuming your source data is on Sheet1 and the destination is Sheet2, and the range of records is lied in A1:E9999 (adapt where necessary):

Sub copy_filtered_data()

'This module copy filtered data from Sheet1 onto Sheet2
With Sheet1
.AutoFilterMode = False
'Filter for records with value of "1" in column A and Copy to destination
With .Range("A1:E9999")
.AutoFilter Field:=1, Criteria1:="1"
.SpecialCells(xlCellTypeVisible).Copy Destination:=Sheet2.Range("A1")
'Lastly, remove the AutoFilter
.Parent.AutoFilterMode = False
End With
End With

End Sub
2014-11-25 8:50 am
Dear Eddie,

Thank you for your answer with clever range selection so that loop selection until meeting of empty cell is not required.


收錄日期: 2021-04-11 20:55:31
原文連結 [永久失效]:
https://hk.answers.yahoo.com/question/index?qid=20141124000051KK00061

檢視 Wayback Machine 備份