VBA pasting macro help

will31

Board Regular
Joined
May 2, 2010
Messages
140
Hi All,

I have the following macro:

Code:
Sub Paste()
'
' Paste Macro
'
Application.ScreenUpdating = False
'Paste AB    Workbooks.Open Filename:= _
        "[URL="file://\\hunnt47\DataRevenInv\R"]NNA[/URL].xlsm", _
        Origin:=xlWindows
    Workbooks("data capture.xlsm").Sheets("AB").Range("A3:J2000").Copy Workbooks("NNA.xlsm").Sheets("Schedule").Range("A2")
'Paste AC
Workbooks("data capture.xlsm").Sheets("AC").Range("A3:J2000").Copy Workbooks("NNA.xlsm").Sheets("Schedule").Range[B][COLOR=red]("A150")
[/COLOR][/B]    Workbooks("NNA.xlsm").Sheets("Schedule").Range("B2").Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.Replace What:=" - IL", Replacement:="", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
    Workbooks("NNA.xlsm").Close savechanges:=True
Application.ScreenUpdating = True
End Sub

Which does what I want it to do but I want to add some more intelligence to the way it works. I'm trying to get it to clear A2 to the last fill cell in comumn J on sheet Schedule in workbook NNA. I can't figure out how to do this.

Also, for the pasting of the data from Data capture into NNA if it is possible for the cell reference in red to be found by find the first unfilled cell in column A that would be great.

Thanks in advance,

Will
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Code:
Sub Paste()
'
' Paste Macro
'

    Dim wsAB As Worksheet: Set wsAB = Workbooks("data capture.xlsm").Sheets("AB")
    
    Application.ScreenUpdating = False
    
    With Workbooks("NNA.xlsm").Sheets("Schedule")
    
        .Range("A2", .Range("J" & Rows.Count).End(xlUp)).ClearContents
        
        wsAB.Range("A3", wsAB.Range("J" & Rows.Count).End(xlUp)).Copy .Range("A2")
    
        .Columns("B:B").Replace What:=" - IL", Replacement:="", _
                                LookAt:=xlPart, SearchOrder:=xlByRows, _
                                MatchCase:=False, SearchFormat:=False, _
                                ReplaceFormat:=False
    End With
    
    Workbooks("NNA.xlsm").Close SaveChanges:=True
    
    Application.ScreenUpdating = True
    
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,514
Messages
6,179,220
Members
452,895
Latest member
BILLING GUY

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top