Advertisement
Guest User

StackOverflowRows

a guest
May 24th, 2017
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.74 KB | None | 0 0
  1. Option Explicit
  2.  
  3. Sub CopyColumns()
  4.  
  5.     Dim CopyFromPath As String, FileName As String
  6.     Dim CopyToWb As Workbook, wb As Workbook, CopyToWs As Worksheet
  7.     Dim lastRow As Long, NextRow As Long, lcol As Long, c As Long, sv As Integer
  8.     Dim ws As Worksheet
  9.     Dim lngRow As Long: lngRow = 1
  10.     Dim myCol As Long
  11.     Dim myHeader As Range
  12.     Application.ScreenUpdating = False
  13.     CopyFromPath = "\\omeshare\HOME0027\3029\My Documents\StoredFolder\"
  14.    Set CopyToWb = ActiveWorkbook
  15.    Set CopyToWs = CopyToWb.Sheets("Master")
  16.    FileName = Dir(CopyFromPath & "*.xlsx")
  17.    Do While Len(FileName) > 0
  18.        Set wb = Workbooks.Open(CopyFromPath & FileName)
  19.        With wb.Sheets("Open Issue Actions")
  20.            lngRow = lngRow + 1
  21.            lcol = .Cells(1, .Columns.Count).End(xlToLeft).Column
  22.            For c = 1 To lcol
  23.                wb.Sheets("Open Issue Actions").Activate
  24.                If .Cells(1, c) = "Issue Type" Or .Cells(1, c) = "Issue DocID" Or .Cells(1, c) = "Country and/or Region" Or .Cells(1, c) = "Issue Title" Or _
  25.                   .Cells(1, c) = "Issue Summary" Or .Cells(1, c) = "Issue Rating" Or _
  26.                   .Cells(1, c) = "Issue Priority" Or .Cells(1, c) = "Issue Business Unit" Or _
  27.                   .Cells(1, c) = "Action Due Date" Or .Cells(1, c) = "Issue Due Date" Or .Cells(1, c) = "Revised Due Date" Or _
  28.                   .Cells(1, c) = "Responsible Business Executive" Or .Cells(1, c) = "Action Delivery Owner" Or _
  29.                   .Cells(1, c) = "Current Update" Or .Cells(1, c) = "Issue / Action" Or _
  30.                   .Cells(1, c) = "APAC / IHC / BICEP" Or .Cells(1, c) = "Horizontal / Vertical" Or _
  31.                   .Cells(1, c) = "1LOD / 2LOD / 3LOD / Reg" Or .Cells(1, c) = "Owned / Impacted" Then
  32.                    lastRow = .Cells(Rows.Count, c).End(xlUp).Row
  33.                    If lastRow = 1 Then GoTo nxt
  34.  
  35.                    Range(Cells(2, c), Cells(lastRow, c)).Copy
  36.                    CopyToWs.Activate
  37.                    Set myHeader = CopyToWs.Rows(1).Find(What:=.Cells(1, c).Value, Lookat:=xlWhole)
  38.                    With CopyToWs
  39.                        If Not myHeader Is Nothing Then
  40.                            myCol = myHeader.Column
  41.                            NextRow = .Cells(Rows.Count, myCol).End(xlUp).Row + 1
  42.                            .Cells(lngRow, myCol).PasteSpecial xlPasteValues
  43.                            Application.CutCopyMode = False
  44.                            Set myHeader = Nothing
  45.                        End If
  46. nxt:
  47.                    End With
  48.                End If
  49.            Next c
  50.            wb.Close saveChanges:=False
  51.        End With
  52.        FileName = Dir
  53.    Loop
  54.    Application.ScreenUpdating = True
  55. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement