如何将批量excel表里面的固定行复制到别一个excel表里面。请大家帮忙,谢谢! 5
找到前期解决办法:这个宏VB首要条件是在同一个工作簿内的多个工作表,假设每个表数据是A列到Z列Sub合并()DimaimsheetAsWorksheetSetaimshe...
找到前期解决办法:这个宏VB首要条件是在同一个工作簿内的多个工作表,假设每个表数据是A列到Z列
Sub 合并()
Dim aimsheet As Worksheet
Set aimsheet = Worksheets.Add(after:=Worksheets(Worksheets.Count))
aimsheet.Name = "合并表"
Dim insertindex As Long
insertindex = 1
Dim i As Integer
For i = 1 To Worksheets.Count - 1
Worksheets(i).Activate
Range("a10:z10").Copy
aimsheet.Cells(insertindex, 1).Insert
insertindex = 1 + insertindex
Next
End Sub
运行后合并表内容全部是第一个工作簿的第10行内容,求解! 展开
Sub 合并()
Dim aimsheet As Worksheet
Set aimsheet = Worksheets.Add(after:=Worksheets(Worksheets.Count))
aimsheet.Name = "合并表"
Dim insertindex As Long
insertindex = 1
Dim i As Integer
For i = 1 To Worksheets.Count - 1
Worksheets(i).Activate
Range("a10:z10").Copy
aimsheet.Cells(insertindex, 1).Insert
insertindex = 1 + insertindex
Next
End Sub
运行后合并表内容全部是第一个工作簿的第10行内容,求解! 展开
展开全部
Public excelPath As String
Public myInt As Integer '公共
Public myName As String '公共
Sub 合并()
excelPath = "C:\Documents and Settings\Administrator\桌面\"
Set s = Application.FileSearch
s.LookIn = excelPath
s.Filename = "waybilldatalist*.xls" ' 此处更改为共有表名>>>>
s.Execute '执行搜索
On Error Resume Next
For i = 1 To s.FoundFiles.Count
myName = s.FoundFiles(i)
myName = Split(myName, "\")(UBound(Split(myName, "\")))
If InStr(myName, "xls") > 0 Then
Set xlApp = CreateObject("Excel.Application") '创建EXCEL对象
Set xlBook = xlApp.Workbooks.Open(excelPath + myName) '打开
xlApp.Visible = True '设置EXCEL对象可见(或不可见)
Set xlsheet = xlApp.Worksheets(Replace(myName, ".xls", "")) '设置活动工作表
Cells(2, 1) = CStr(Cells(2, 1) + xlApp.Cells(8, 4)) '操作>>>>
xlBook.Save
xlBook.Close
End If
End If
Next i
End Sub
上面是模板,你改两个>>>>地方就可以用。
s.Filename = "waybilldatalist*.xls" '要改,不知道你表名是什么
Cells(2, 1) = CStr(Cells(2, 1) + xlApp.Cells(8, 4)) '操作部分要改,另外不知道你数据类型,多少列?
Public myInt As Integer '公共
Public myName As String '公共
Sub 合并()
excelPath = "C:\Documents and Settings\Administrator\桌面\"
Set s = Application.FileSearch
s.LookIn = excelPath
s.Filename = "waybilldatalist*.xls" ' 此处更改为共有表名>>>>
s.Execute '执行搜索
On Error Resume Next
For i = 1 To s.FoundFiles.Count
myName = s.FoundFiles(i)
myName = Split(myName, "\")(UBound(Split(myName, "\")))
If InStr(myName, "xls") > 0 Then
Set xlApp = CreateObject("Excel.Application") '创建EXCEL对象
Set xlBook = xlApp.Workbooks.Open(excelPath + myName) '打开
xlApp.Visible = True '设置EXCEL对象可见(或不可见)
Set xlsheet = xlApp.Worksheets(Replace(myName, ".xls", "")) '设置活动工作表
Cells(2, 1) = CStr(Cells(2, 1) + xlApp.Cells(8, 4)) '操作>>>>
xlBook.Save
xlBook.Close
End If
End If
Next i
End Sub
上面是模板,你改两个>>>>地方就可以用。
s.Filename = "waybilldatalist*.xls" '要改,不知道你表名是什么
Cells(2, 1) = CStr(Cells(2, 1) + xlApp.Cells(8, 4)) '操作部分要改,另外不知道你数据类型,多少列?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询