+ Reply to Thread
Results 1 to 14 of 14

need help on vba code which work corresponding files depends upon file name

Hybrid View

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

    need help on vba code which work corresponding files depends upon file name

    Dear expert

    i have set of data range in master A:H i want split value in a col combination of hypen values to closed workbooks of A,B,C,D,....Etc depends upon list of filenames in col H:H.

    like if file name is A.xlsb in H col this code run to particular row to A workbook
    For Each cell In Sheets("Master").Range("A2:A200") *need to change master sheet as active workbook
    
          If InStr(cell, "-451414-") Then Sheets("RECK").Cells(65000, "E").End(xlUp).Offset(1).Resize(, 12) = Application.Index(Split(Join(Array(Replace$(Replace$(cell, "-0-", "-000000-"), "-", "|"), "00000000", "000", "MAY-15", "USD", "AMOUNT", cell.Offset(, 3), "NO"), "|"), "|"), Array(1, 3, 2, 4, 5, 6, 7, 8, 9, 10, 11, 12))
      Next cell
    End With
    Find the attachment.
    Attached Files Attached Files

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

    Re: need help on vba code which work corresponding files depends upon file name

    any experts help on this need urgently!! This thread already in above my post i wrong posted twice i could delete first one so please consider this actual thread!!

  3. #3
    Valued Forum Contributor
    Join Date
    12-02-2012
    Location
    Melbourne, VIC
    MS-Off Ver
    Excel 2016
    Posts
    750

    Re: need help on vba code which work corresponding files depends upon file name

    Does this perform the desired operation:
    Sub Sample()
    
    Dim wbA As Workbook, wbB As Workbook, wbM As Workbook
    Dim sFilePath As String, rCell As Range, sWB As String
    
    Set wbM = ThisWorkbook 'The Master Workbook
    sFilePath = "C:\Users\Admin\Desktop\Oracle\USD\FYD.xlsb" 'hard coded version (left unchanged from your code sample)
    Set wbA = Workbooks.Open(Filename:=sFilePath & "\" & A.xlsb) 'Amend as necessary
    Set wbB = Workbooks.Open(Filename:=sFilePath & "\" & B.xlsb) 'Amend as necessary
    
    For Each rCell In wbM.Worksheets("Master").Range("A2:A200")
         If InStr(rCell, "-451414-") > 0 Then
              sWB = rCell.Offset(7, 0)
              With Excel.Workbooks(sWB)
                   .Worksheets("REK").Range("E65000").End(xlUp).Offset(1).Resize(, 12) = _
                   Application.Index(Split(Join(Array(Replace$(Replace$(rCell, "-0-", "-000000-"), "-", "|"), "00000000", "000", "MAY-15", "USD", "AMOUNT", rCell.Offset(, 3), "NO"), "|"), "|"), Array(1, 3, 2, 4, 5, 6, 7, 8, 9, 10, 11, 12))
                   End With
              End If
         Next
    End Sub

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

    Re: need help on vba code which work corresponding files depends upon file name

    hi sir i getting error while run
    Attached Images Attached Images
    Last edited by breadwinner; 02-29-2016 at 06:00 AM. Reason: atta

  5. #5
    Valued Forum Contributor
    Join Date
    12-02-2012
    Location
    Melbourne, VIC
    MS-Off Ver
    Excel 2016
    Posts
    750

    Re: need help on vba code which work corresponding files depends upon file name

    sFilePath = "C:\Users\Admin\Desktop\Oracle\USD\FYD.xlsb"
    the above line should be amended to point to the directory/folder that has the "A.xlsb" and "B.xlsb' files.

    So, if you have these files on your desktop, replace the above line of code with this one:
    sFilePath = "C:\Users\Admin\Desktop"

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

    Re: need help on vba code which work corresponding files depends upon file name

    Dear sir

    sorry for disturbing you again i getting error 424 even though i saved A&B file in folder "F" and path is "C:\Users\Admin\Desktop\Oracle\Forum\Download\F"

    Thanks
    Attached Images Attached Images
    Last edited by breadwinner; 03-01-2016 at 12:25 AM. Reason: pic

  7. #7
    Valued Forum Contributor
    Join Date
    12-02-2012
    Location
    Melbourne, VIC
    MS-Off Ver
    Excel 2016
    Posts
    750

    Re: need help on vba code which work corresponding files depends upon file name

    I'm not sure, but the Directory Path maybe case-sensitive. You have a small "f" in the code, but a caps "F" in the path mentioned. Try changing "f" to "F" in the code.

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

    Re: need help on vba code which work corresponding files depends upon file name

    No sir its small "f" only eventhough i getting error same i wrong quoted as "F". but it doesnt contrain the small or big alphs
    this is path now C:\Users\Admin\Desktop\Oracle\Forum\Scrap In scrap folder i save all files

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

    Re: need help on vba code which work corresponding files depends upon file name

    Sir last question if i add more files line up after A&B like C,D,E,F..Etc. How do i addi just try myself.
    here
    If wb.Name = "C.xlsb" Then Set wbB = wb
         If wb.Name = "D.xlsb" Then Set wbB = wb
    here
    
    If wbB Is Nothing Then Set wbB = Excel.Workbooks.Open(Filename:=sFilePath & "\" & "C.xlsb")
    If wbB Is Nothing Then Set wbB = Excel.Workbooks.Open(Filename:=sFilePath & "\" & "D.xlsb")
    
    here
     If sWB = "A.xlsb" Or sWB = "B.xlsb" Or sWB = "C.xlsb" Or sWB = "D.xlsb" Then
    pls advice me sir

  10. #10
    Valued Forum Contributor
    Join Date
    12-02-2012
    Location
    Melbourne, VIC
    MS-Off Ver
    Excel 2016
    Posts
    750

    Re: need help on vba code which work corresponding files depends upon file name

    firstly, declare new variables ... wbC as Workbook ... and so on, then add suitable conditions in the code (as you identified)
    If wb.Name = "C.xlsb" Then Set wbC = wb
    
    If wbC Is Nothing Then Set wbC = Excel.Workbooks.Open(Filename:=sFilePath & "\" & "C.xlsb")
    
    If sWB = "A.xlsb" Or sWB = "B.xlsb" Or sWB = "C.xlsb" Or sWB = "D.xlsb" Then  'This approach is fine

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

    Re: need help on vba code which work corresponding files depends upon file name

    Nice!! Amazing sir works perfectly!!!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. need vba code to split rows to closed wb shets depends company code met with sht name
    By julielara in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-18-2016, 12:44 PM
  2. VBA code to insert data from multiple .txt files into one output file template file
    By psmith33 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-04-2015, 02:49 PM
  3. [SOLVED] VBA code to open many files, copy text, close file, paste text in second work
    By Bikeman in forum Excel Programming / VBA / Macros
    Replies: 27
    Last Post: 02-11-2014, 12:59 PM
  4. Replies: 2
    Last Post: 02-10-2014, 11:52 AM
  5. [SOLVED] Modify code to work with xls and xlsx files
    By CJ-22 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 08-31-2013, 11:21 AM
  6. VBa code to open files from two different folders and work on them simultaneously
    By rumshar in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-19-2013, 09:41 AM
  7. Update Code to work between 2 files
    By dkenebre in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-12-2005, 10:34 AM

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