首页 > 代码库 > Excel VBA 操作 复制拷贝操作

Excel VBA 操作 复制拷贝操作

Attribute VB_Name = "模块11"Dim inputdate As StringDim newbook As WorkbookSub 提取数据()Dim ws As WorksheetDim datestr As StringDim phone As StringDim money As StringDim goods As StringDim newws As WorksheetDim moneyint As Integerinputdate = InputBox("请输入导出日期")If inputdate = "" Then EndDim name As Stringname = Format(inputdate, "m-d")Set ws = Worksheets(1)Set newbook = Workbooks.Addnewbook.SaveAs Filename:=name & ".xlsx"ThisWorkbook.Sheets.Add After:=Worksheets(Worksheets.Count) ‘添加一个新工作表在第一工作表前Set newws = newbook.Worksheets(1)newws.Cells(1, 1) = "手机号码"newws.Cells(1, 2) = "金额"newws.Cells(1, 3) = "产品"newws.Cells(1, 4) = "日期"newws.Range("A1:A65536").ColumnWidth = 50newws.Range("B1:B65536").ColumnWidth = 50newws.Range("C1:C65536").ColumnWidth = 50newws.Range("D1:D65536").ColumnWidth = 50newws.Range("A1:A65536").HorizontalAlignment = Excel.xlCenternewws.Range("B1:B65536").HorizontalAlignment = Excel.xlCenternewws.Range("C1:C65536").HorizontalAlignment = Excel.xlCenternewws.Range("D1").HorizontalAlignment = Excel.xlCenternewws.Range("D2:D65536").HorizontalAlignment = Excel.xlLeftnewws.Range("A1:A65536").NumberFormatLocal = "@"newws.Range("B1:B65536").NumberFormatLocal = "@"newws.Range("C1:C65536").NumberFormatLocal = "@"newws.Range("D1:D65536").NumberFormatLocal = "@"Dim n As IntegerDim m As Integern = 2m = 2Dodatestr = ws.Cells(n, 10)If datestr = inputdate Thenphone = ws.Cells(n, 26)money = ws.Cells(n, 8)goods = ws.Cells(n, 7)newws.Cells(m, 1) = phonemoney = Format$(money, "Standard")newws.Cells(m, 2) = moneynewws.Cells(m, 3) = goodsnewws.Cells(m, 4) = datestrm = m + 1End Ifn = n + 1Loop Until n = ws.UsedRange.Rows.Count + 1End Sub

 

Excel VBA 操作 复制拷贝操作