现在有两个表,在1.xls中,A列有两种连续数据,两种数据中间有一个空白单元格隔开,我现在想做的是将A列复制到2.xls中并且分两列显示,请问该怎么写呢?程序请以2.xls为准写。
Sub AAA()
Dim Sh1 As Worksheet
Dim Sh2 As Worksheet
Set Sh1 = Workbooks("1.XLS").Sheets(1)
Set Sh2 = Workbooks("2.XLS").Sheets(1)
Sh1.Range(Sh1.[A1], Sh1.Range("A1").End(xlDown)).Copy Sh2.[A1]
Sh1.Range(Sh1.[A65536].End(xlUp), Sh1.[A65536].End(xlUp).End(xlUp)).Copy Sh2.[B1]
End Sub
Dim Sh1 As Worksheet
Dim Sh2 As Worksheet
Set Sh1 = Workbooks("1.XLS").Sheets(1)
Set Sh2 = Workbooks("2.XLS").Sheets(1)
Sh1.Range(Sh1.[A2], Sh1.Range("A1").End(xlDown)).Copy Sh2.[A1]
Sh1.Range(Sh1.[A65536].End(xlUp), Sh1.[A65536].End(xlUp).End(xlUp).Offset(1)).Copy Sh2.[B1]
End Sub
Dim Sh1 As Worksheet
Dim Sh2 As Worksheet
Set Sh1 = Workbooks("1.XLS").Sheets(1)
Set Sh2 = Workbooks("2.XLS").Sheets(1)
Sh1.Range(Sh1.[A1], Sh1.Range("A1").End(xlDown)).Copy Sh2.[A1]
Sh1.Range(Sh1.[A65536].End(xlUp), Sh1.[A65536].End(xlUp).End(xlUp)).Copy Sh2.[B1]
End Sub
随便放哪个工作簿吧。但是,两个工作簿都要打开。当然你也可以加上打开工作簿的代码。
我错了,我该说的更明确一点...我的A列的两种数据都有一个title在数据上方一个单元格,复制的时候不要title,所以第一种可以从A2开始,但是第二种数据从下往上的话不是就把title复制到了么
追答Sub AAA()Dim Sh1 As Worksheet
Dim Sh2 As Worksheet
Set Sh1 = Workbooks("1.XLS").Sheets(1)
Set Sh2 = Workbooks("2.XLS").Sheets(1)
Sh1.Range(Sh1.[A2], Sh1.Range("A1").End(xlDown)).Copy Sh2.[A1]
Sh1.Range(Sh1.[A65536].End(xlUp), Sh1.[A65536].End(xlUp).End(xlUp).Offset(1)).Copy Sh2.[B1]
End Sub
温馨提示:答案为网友推荐,仅供参考
第1个回答 2013-07-31
Sub test()
Dim row1 As Integer
Dim row2 As Integer
row1 = Sheets("1").Cells(1, 1).End(xlDown).Row
row2 = Sheets("1").Cells(65536, 1).End(xlUp).Row
Sheets("1").Range("A1:A" & row1).Copy Sheets("2").Cells(1, 1)
Sheets("1").Range("A" & row1 + 2 & ":A" & row2).Copy Sheets("2").Cells(1, 2)
End Sub
已经通过验证。
Dim row1 As Integer
Dim row2 As Integer
row1 = Sheets("1").Cells(1, 1).End(xlDown).Row
row2 = Sheets("1").Cells(65536, 1).End(xlUp).Row
Sheets("1").Range("A1:A" & row1).Copy Sheets("2").Cells(1, 1)
Sheets("1").Range("A" & row1 + 2 & ":A" & row2).Copy Sheets("2").Cells(1, 2)
End Sub
已经通过验证。
第2个回答 2013-07-31
最好有附件啊,能上附件吗