Results 1 to 3 of 3

VBA pull data from closed wb through header names & make condition changes in H&AL col

Threaded View

  1. #1
    Forum Contributor
    Join Date
    07-21-2011
    Location
    Bangalore,India
    MS-Off Ver
    Excel 2007,2010,2016
    Posts
    695

    VBA pull data from closed wb through header names & make condition changes in H&AL col

    Dear Experts

    I have saved master workbook in particular folder with the range of A:AR columns .. i want pull values from master workbook into another workbook only desired column header through vba with two changes in H& AL columns,,

    In the H:H column "CALL TYPE" in that where ever LABOR ONLY & LABOR & PART values change as "BRING IN"..
    and In the AL:AL column "PRIORITY" in that entire row apply this formula
    "IFERROR(IF(AND(AG2="A 0-2 Days",AI2="E 16-20 Days"),"1",IF(AND(AG2="A 0-2 Days",AI2="F 21-30 Days"),"1",IF(AND(AG2="A 0-2 Days",AI2="G >30 Days"),"1",IF(AND(AG2="B 3-5 Days",AI2="E 16-20 Days"),"1",IF(AND(AG2="B 3-5 Days",AI2="F 21-30 Days"),"1",IF(AND(AG2="B 3-5 Days",AI2="G >30 Days"),"1",IF(AG2="A 0-2 Days","3",IF(AG2="B 3-5 Days","2",IF(AG2="C 6-10 Days","1",IF(AG2="D 11-15 Days","1",IF(AG2="E 16-20 Days","1",IF(AG2="F 21-30 Days","1",IF(AG2="G >30 Days","1"," ")))))))))))))," ")"

    find the attachment...Master & Qubic.xlsb

    below code to pull data from masterfile stored in "strFolderPath"
    
    Sub BRINGINCASES()
    
    Dim strFolderPath         As String
    Dim strFile               As String
    Dim wbNew                 As Workbook
    Dim wsTarg                As Worksheet
    Dim CalcMode              As Long
    Dim lngLastRow            As Long
    Dim lngTargRow            As Long
    Dim Rng                   As Range
    Dim rngCell               As Range
    Dim rngFound              As Range
    Dim strAddr               As String
    Dim rngDouble             As Range
    
    Const cstrEXT_XL          As String = "*.xlsb"
    Const cstrSEARCH          As String = "A1:AC1"
    
    With Application   ' Set various application properties.
      CalcMode = .Calculation
      .Calculation = xlCalculationManual
      .ScreenUpdating = False
      .AskToUpdateLinks = False
      .EnableEvents = False
      .DisplayAlerts = False
    End With
    
    Set wsTarg = ThisWorkbook.Sheets("CCI-BRINGIN") 'Imports the data into the activesheet. Change to suit
    wsTarg.Range("A2:bk" & Rows.Count).ClearContents
    
    'Initialise the following varibales to the first *.xls file in the designated folder
    strFolderPath = "C:\Users\mani\Desktop\MALLI\Oops" 'Change to your own path
    If Right(strFolderPath, 1) <> "\" Then ' Add a slash at the end of the path if needed.
      strFolderPath = strFolderPath & "\"
    End If
    
    strFile = Dir(strFolderPath & cstrEXT_XL) 'Excel file types to import due to Constant
    
    Do Until strFile = ""
      lngTargRow = wsTarg.Cells.Find("*", , , , xlByRows, xlPrevious).Row + 1
      Set wbNew = Workbooks.Open(strFolderPath & strFile)
      Set Rng = wbNew.Worksheets("OPENCALL").Range("A1:DD1")
      lngLastRow = wbNew.Worksheets("OPENCALL").Cells.Find("*", , , , xlByRows, xlPrevious).Row
      For Each rngCell In wsTarg.Range(cstrSEARCH)
        If WorksheetFunction.CountIf(wsTarg.Range("A1", rngCell), rngCell) = 1 Then
          Set rngFound = Rng.Find(rngCell, Rng.Cells(Rng.Cells.Count), xlValues, xlWhole)
          If Not rngFound Is Nothing Then
            wsTarg.Cells(lngTargRow, rngCell.Column).Resize(lngLastRow - 1, 1).Value = rngFound.Offset(1).Resize(lngLastRow - 1).Value
            If WorksheetFunction.CountIf(wsTarg.Range("A1:bk1"), rngCell) > 1 Then
              strAddr = rngCell.Address
              Set rngDouble = rngCell
              Do
                Set rngDouble = wsTarg.Range(cstrSEARCH).FindNext(After:=rngDouble)
                If Not rngDouble Is Nothing Then
                  Set rngFound = Cells.FindNext(After:=rngFound)
                  wsTarg.Cells(lngTargRow, rngDouble.Column).Resize(lngLastRow - 1, 1).Value = rngFound.Offset(1).Resize(lngLastRow - 1).Value
                End If
              Loop While rngDouble.Address <> strAddr
              strAddr = ""
            End If
          End If
        End If
      Next rngCell
      wsTarg.Cells(lngTargRow, "AP").Resize(lngLastRow - 1) = strFile
      wbNew.Close savechanges:=False
      
      strFile = Dir()
    
    Loop
    
    With Application
      .ScreenUpdating = True
      .EnableEvents = True
      .Calculation = CalcMode
      .AskToUpdateLinks = True
      .DisplayAlerts = True
    End With
    Attached Files Attached Files

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Pull data from closed workbook issue
    By mattress58 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-14-2014, 11:59 AM
  2. [SOLVED] VBA pull data from closed workbook depends upon header status !!! need help of experts
    By johnodys in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 08-12-2013, 07:06 AM
  3. Replies: 2
    Last Post: 07-25-2012, 04:15 PM
  4. Use VBA to pull data from another closed workbook
    By derryt in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-08-2012, 11:09 AM
  5. Using ADO to pull data from closed workbook.
    By abhay_547 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-06-2010, 06:20 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1