|
求助各位大神哥哥,姐姐,我想通过宏按钮“开始汇总”将一张工作表中的5个sheet的内容按照要求(比如说只要客户代码,客户名称,数量,RMB单价这些数据)提取到另一张新的工作表中,之前写过一个将所有内容复制过去的一个代码,不知道可不可以在这个代码的基础上改一改。基本思路是:点击“开始汇总”按钮,打开对话框并选择文件,开始汇总
Private Sub CommandButton1_Click()
Dim file1 As String
Dim cnt1, s, n, t, m As Integer
Dim RNG1, RNG2 As Range
Dim strFolder As String
Dim wbk001 As Workbook
With Application.FileDialog(msoFileDialogFilePicker)
.Title = "选择导入文件"
.AllowMultiSelect = False
.InitialFileName = "d:\" '默认路径
If .Show Then
strFolder = .SelectedItems(1)
End If
End With
Set wbk001 = Workbooks.Open(strFolder)
cnt1 = wbk001.Sheets.Count
wbk001.Sheets(1).Rows(1).Copy
ThisWorkbook.Sheets(1).Rows(1).PasteSpecial xlPasteColumnWidths
ThisWorkbook.Sheets(1).Rows(1).PasteSpecial xlPasteAll
ThisWorkbook.Sheets(1).Rows(1).RowHeight = 50
ThisWorkbook.Sheets(1).Rows(1).VerticalAlignment = xlBottom
m = ThisWorkbook.Sheets(1).Cells(65536, 2).End(xlUp).Row
m = m + 1
For s = 1 To cnt1
t = wbk001.Sheets(s).Cells(65536, 2).End(xlUp).Row
For n = 2 To t
Set RNG1 = wbk001.Sheets(s).Range("A" & n & ":AQ" & n)
Set RNG2 = ThisWorkbook.Sheets(1).Range("A" & m & ":AQ" & m)
RNG1.Copy RNG2
m = m + 1
Next
Next
Dim C As Range
Set C = Range("A:A", "AQ:AQ")
C.HorizontalAlignment = xlCenter
With ThisWorkbook.Sheets(1)
.Columns.AutoFit
.Rows.AutoFit
End With
ThisWorkbook.Sheets(1).Rows(1).RowHeight = 50
wbk001.Save
End Sub
|
|