写一段VBA代码,将所有打开的工作簿中的同一sheet中的B列数据按顺序插入到新工作簿中。
时间: 2023-03-11 22:34:15 浏览: 207
vba:根据一个sheet内容批量替换整个工作簿
Sub InsertB()
Dim wb As Workbook
Dim wb2 As Workbook
Dim ws As Worksheet
Dim ws2 As Worksheet
Dim j As Integer
Dim i As Integer
Set wb = ActiveWorkbook
Set ws = wb.ActiveSheetSet wb2 = Workbooks.Add
Set ws2 = wb2.ActiveSheetj = 1For i = 1 To wb.Sheets.Count
wb.Sheets(i).Select
ws.Range("B1").CurrentRegion.Copy
ws2.Range("A" & j).PasteSpecial
j = j + ws.Range("B1").CurrentRegion.Rows.Count
Next iEnd Sub
阅读全文