Reading multiple columns Workbook 1, to paste in single column Workbook 2

John.McLaughlin

Board Regular
Joined
Jul 19, 2011
Messages
169
Why do I keep pasting to the first 5 columns, instead of finding the last empty row in column A?

Thanks in advance!

VBA Code:
Sub PostTools()


' TOOLSPost - post from OPEN ORDER TOOLS SS to Scheduled TOOLS SS
'
'
   ' Copy items to sheet.
   '
   '
   Application.ScreenUpdating = False
  
   Dim wbTarget            As Workbook 'workbook where the data is to be pasted SCHEDULED:TOOLS
   Dim wbThis              As Workbook 'workbook from where the data is to copied Open Order"Tools
   Dim strName             As String   'name of the source sheet/ target workbook
   Dim filelink            As String   ' name of workbook
   Dim targetFile As String
  
' ----------------- Find last row
    Dim DstRng As Range
    Dim DstWks As Worksheet
    Dim LastRow As Long
    Dim N As Long, r As Long
    Dim SrcRng As Range
    Dim SrcWks As Worksheet
' ------------------ End find last row

   'set to the current active workbook (the source book - Open Order)
   Set wbThis = ActiveWorkbook

   'unhide TOOLS sheet in the Open Order workbook and select it
    Sheets("TOOLS").Visible = True
    Sheets("TOOLS").Select
   
   'get the active sheetname of the Open Order workbook
   strName = ActiveSheet.Name
   

    ' Activate the Scheduled Workbook and select the Tools worksheet
    Workbooks("SCHEDULED.xlsm").Activate
    Set wbTarget = ActiveWorkbook
    Sheets("TOOLS").Select

 
   'activate the Open Order source book
   wbThis.Activate
   
   'clear any thing on clipboard to maximize available memory
   Application.CutCopyMode = False
   
  
  ' copy the range from source book
    wbThis.Sheets("TOOLS").Range("A5:Z5").Copy
  
  

' Assign the Worksheets
        Set SrcWks = wbThis.Sheets("TOOLS")
        Set DstWks = wbTarget.Sheets("TOOLS")
       
' Get all cells in the Source Range starting with row 5
        Set SrcRng = SrcWks.Range("A5:Z5")
        LastRow = SrcWks.Cells(Rows.Count, "B").End(xlUp).Row
        If LastRow < SrcRng.Row Then Exit Sub Else Set SrcRng = SrcRng.Resize(LastRow - SrcRng.Row + 1, 26)
       
       
' Find the next empty row in the Destination Range starting at row 3
       
        ' Set DstRng = DstWks.Range("A3:E3")
        Set DstRng = DstWks.Range("A3:A3")
        LastRow = DstWks.Cells(Rows.Count, "A").End(xlUp).Row
        Set DstRng = IIf(LastRow < DstRng.Row, DstRng, DstRng.Offset(LastRow - DstRng.Row + 1, 0))
       
          ' Copy the Source cells to the next empty Destination row if the Source Cell in "A" is not empty
         
            For r = 1 To SrcRng.Rows.Count
                If SrcRng.Cells(r, "A") <> "" Then
                    DstRng.Offset(N, 0).Resize(, 5).Value = SrcRng.Rows(r).Value
                  
                   N = N + 1
                End If
            Next r
       
      
      
      
   'clear any thing on clipboard to maximize available memory
   Application.CutCopyMode = False
   
   'save the target book
   wbTarget.Save

   'activate the source book again
   wbThis.Activate

    'hide TOOLS sheet and select order sheet
    Sheets("TOOLS").Visible = False
    Sheets("ORDER").Select
   


Application.CutCopyMode = False
Application.ScreenUpdating = True
Range("A1").Select

wbThis.Activate
ActiveSheet.Unprotect
Range("F30").Select
    With Selection.Font
        .Name = "Trebuchet MS"
        .FontStyle = "Bold"
        .Size = 10
        .Strikethrough = False
        .Superscript = False
        .Subscript = False
        .OutlineFont = False
        .Shadow = False
        .Underline = xlUnderlineStyleNone
        .Color = 5287936
        .TintAndShade = 0
        .ThemeFont = xlThemeFontNone
    End With

[ORDER!H$30].Value = Now()

ActiveSheet.Protect DrawingObjects:=False, Contents:=True, Scenarios:= _
        False
       
Application.CutCopyMode = False
Application.ScreenUpdating = True
Set wbTarget = Nothing
Set wbThis = Nothing


End Sub
 
Last edited by a moderator:

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
If I toggle this 5 value to 1, it will paste into column A of the target workbook, but not the additional columns from the source range

Code:
                    DstRng.Offset(N, 0).Resize(, 5).Value = SrcRng.Rows(r).Value
 
Upvote 0
I don't think this matters, but each column is rows of Index/matches from a part no table. I just want to recap into a single column for a daily report .

Thanks for your help!
 
Upvote 0

Forum statistics

Threads
1,214,651
Messages
6,120,739
Members
448,989
Latest member
mariah3

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