D
Dan R.
This code simply copies a range from WB1 and pastes into into the
first empty column in WB2.Sheet2 then saves WB2, but right before WB2
is closed I need it to copy WB2.Sheet2.Cells(A1:J3) and paste it in
the same column that the other range was pasted. Can someone help me
with this please?
Here's my code:
Sub Copy()
Dim SourceRange As Range
Dim DestRange1 As Range
Dim DestRange2 As Range
Dim BANCol As Range
Dim LC1 As Integer
Dim LC2 As Integer
Dim WB1 As Worksheet
Dim WB2 As Workbook
Application.ScreenUpdating = False
Set WB1 = ActiveSheet
Set WB2 = Workbooks.Open("C:\Documents and Settings\Totals.xls")
LC1 = Lastcol(WB2.Sheets(2)) + 1
LC2 = Lastcol(WB2.Sheets(1))
Set SourceRange = WB1.Columns("A:K")
Set DestRange1 = WB2.Sheets(2).Columns(LC1)
Set DestRange2 = WB2.Sheets(1).Columns(LC2)
SourceRange.Copy DestRange1
DestRange2.Insert
Set BANCol = WB2.Sheets(2).Columns(LC1 + 4)
BANCol.EntireColumn.Delete
WB2.Close savechanges:=True
Application.ScreenUpdating = True
End Sub
Function Lastcol(sh As Worksheet)
On Error Resume Next
Lastcol = sh.Cells.Find(What:="*", _
After:=sh.Range("A1"), _
Lookat:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByColumns, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Column
On Error GoTo 0
End Function
Thank You,
-- Dan
first empty column in WB2.Sheet2 then saves WB2, but right before WB2
is closed I need it to copy WB2.Sheet2.Cells(A1:J3) and paste it in
the same column that the other range was pasted. Can someone help me
with this please?
Here's my code:
Sub Copy()
Dim SourceRange As Range
Dim DestRange1 As Range
Dim DestRange2 As Range
Dim BANCol As Range
Dim LC1 As Integer
Dim LC2 As Integer
Dim WB1 As Worksheet
Dim WB2 As Workbook
Application.ScreenUpdating = False
Set WB1 = ActiveSheet
Set WB2 = Workbooks.Open("C:\Documents and Settings\Totals.xls")
LC1 = Lastcol(WB2.Sheets(2)) + 1
LC2 = Lastcol(WB2.Sheets(1))
Set SourceRange = WB1.Columns("A:K")
Set DestRange1 = WB2.Sheets(2).Columns(LC1)
Set DestRange2 = WB2.Sheets(1).Columns(LC2)
SourceRange.Copy DestRange1
DestRange2.Insert
Set BANCol = WB2.Sheets(2).Columns(LC1 + 4)
BANCol.EntireColumn.Delete
WB2.Close savechanges:=True
Application.ScreenUpdating = True
End Sub
Function Lastcol(sh As Worksheet)
On Error Resume Next
Lastcol = sh.Cells.Find(What:="*", _
After:=sh.Range("A1"), _
Lookat:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByColumns, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Column
On Error GoTo 0
End Function
Thank You,
-- Dan