+ Reply to Thread
Results 1 to 14 of 14

extract range has a missing or illegal field name

Hybrid View

  1. #1
    Registered User
    Join Date
    12-06-2012
    Location
    Richmond, VA
    MS-Off Ver
    Excel 2019
    Posts
    80

    extract range has a missing or illegal field name

    I saw some threads with advice on how to fix this, but nothing helped. I'm also very new to VBA and creating macros, so I have a feeling this will have more bugs.

    Basically, what I want to do is separate the data in Sheet 1 by category 'EmployeeNo.' After that, I'll also need a second macro that consolidates this data back into the same file, but I'll work on that later.

    Any help would be greatly appreciated. Thanks!

    File1.xlsm

    By the way, I updated the attachment, but am unable to remove the previous one, so please follow the link 'File1.'
    Attached Files Attached Files
    Last edited by Drexl27; 10-08-2015 at 09:04 AM.

  2. #2
    Forum Expert skywriter's Avatar
    Join Date
    06-09-2014
    Location
    USA
    MS-Off Ver
    365 Version 2409
    Posts
    2,789

    Re: extract range has a missing or illegal field name

    Basically, what I want to do is separate the data in Sheet 1 by category 'EmployeeNo.'
    Care to elaborate?

  3. #3
    Registered User
    Join Date
    12-06-2012
    Location
    Richmond, VA
    MS-Off Ver
    Excel 2019
    Posts
    80

    Re: extract range has a missing or illegal field name

    I want this macro to separate the data by the category 'EmployeeNo' each into its own file in the same folder. I also just figured now that it would be preferable to name each file by employee name. So after running the macro, there should then be a separate file for 'Ashby' (last name of an employee) with all of the data contained in the rows that EmployeeNo '100003' is on. After that, I also want to create a separate macro that will consolidate these files back (after they've been manipulated by someone else).

  4. #4
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: extract range has a missing or illegal field name

    Try
    Sub test()
        Dim ws As Worksheet, a, i As Long, myName As String, dic As Object
        Application.ScreenUpdating = False
        Set dic = CreateObject("Scripting.Dictionary")
        Set ws = Sheets.Add
        With Sheets("sheet1").Cells(1).CurrentRegion
            a = .Columns("g").Value
            For i = 2 To UBound(a, 1)
                If Not dic.exists(a(i, 1)) Then
                    dic(a(i, 1)) = Empty
                    myName = a(i, 1) & "_" & Split(.Cells(i, 6).Value, ",")(0) & ".xlsx"
                    ws.Name = Split(.Cells(i, 1).Value, ",")(0)
                    ws.Cells.Clear
                    .AutoFilter 7, a(i, 1)
                    .Copy ws.Cells(1)
                    ws.Copy
                    ActiveWorkbook.SaveAs ThisWorkbook.Path & "\" & myName
                    ActiveWorkbook.Close False
                    .AutoFilter
                End If
            Next
        End With
        Application.DisplayAlerts = False
        ws.Delete
        Application.DisplayAlerts = True
        Application.ScreenUpdating = True
    End Sub

  5. #5
    Registered User
    Join Date
    12-06-2012
    Location
    Richmond, VA
    MS-Off Ver
    Excel 2019
    Posts
    80

    Re: extract range has a missing or illegal field name

    Well, that works much better than what I had working before with a different workbook. Thanks much for that - much appreciated.

    If anyone has a chance, please look at the new attached workbook and see if you can find what's wrong with the 'ConsolidateFiles' macro. Once the extraction that jindon created occurs, I want to then consolidate the data from all those previouslly extracted files back into a new sheet within the original workbook. Thanks.

    File2.xlsm

  6. #6
    Forum Expert skywriter's Avatar
    Join Date
    06-09-2014
    Location
    USA
    MS-Off Ver
    365 Version 2409
    Posts
    2,789

    Re: extract range has a missing or illegal field name

    This code is populating the array with the values from column L, "Current Year Budget", including the header row.
    Dim myArr() As Variant: Let myArr() = ws1.Columns(ws1.Cells(2, Columns.Count).End(xlToLeft).Column).SpecialCells(xlCellTypeConstants).Value

  7. #7
    Registered User
    Join Date
    12-06-2012
    Location
    Richmond, VA
    MS-Off Ver
    Excel 2019
    Posts
    80

    Re: extract range has a missing or illegal field name

    Well, the error I receive gives the path for the folder that the file is in followed by '\Row Labels.xlsx cannot be found. Check your spelling, or try a different path. I think there's an issue with the following code:

    Workbooks.Open Filename:=wbHere.Path & "\" & myArr(Cnt, 1) & ".xlsx"

    P.S. I'm still a novice learning VBA as I go. This code is mostly copied from a different workbook, and I'm just trying to edit it properly to work with this one.

  8. #8
    Forum Expert skywriter's Avatar
    Join Date
    06-09-2014
    Location
    USA
    MS-Off Ver
    365 Version 2409
    Posts
    2,789

    Re: extract range has a missing or illegal field name

    Workbooks.Open Filename:=wbHere.Path & "\" & myArr(Cnt, 1) & ".xlsx"
    Read my post again, look at the data in your spreadsheet, specifically regarding what I said about the data that's being put into the array, then look at what you just posted.

    Workbooks.Open Filename:=wbHere.Path & "\" & myArr(Cnt, 1) & ".xlsx"

  9. #9
    Registered User
    Join Date
    12-06-2012
    Location
    Richmond, VA
    MS-Off Ver
    Excel 2019
    Posts
    80

    Re: extract range has a missing or illegal field name

    Sorry, I'm looking at this code, what you wrote, and the code from the previous workbook where it worked, and I still don't fully understand what's wrong with it.

  10. #10
    Forum Expert skywriter's Avatar
    Join Date
    06-09-2014
    Location
    USA
    MS-Off Ver
    365 Version 2409
    Posts
    2,789

    Re: extract range has a missing or illegal field name

    The file you uploaded in post #5 has in column L of Sheet1 some data.
    The header is "Current Year Budget", then there is some data, 400, 275, 400 again etc.

    In that same post you have this:
    If anyone has a chance, please look at the new attached workbook and see if you can find what's wrong with the 'ConsolidateFiles' macro.
    That code is from that macro. MyArr is an array of values.
    The values that are filling that array are, because of the way the code is written, coming from that column.

    Therefore the first item in the array is "Current Year Budget", the second item is 400, the third item is 275, look at the file you posted in column L.

    Now the code is trying to open a file
    Workbooks.Open Filename:=wbHere.Path & "\" & myArr(Cnt, 1) & ".xlsx"
    Notice where is says myArr? So the first time it loops it's looking for a file that ends in Current Year Budget.xlsx, you say your error is Row Labels.xlsx, so I think you are not using the file you posted because I don't find the text rowlabels anywhere in the file, but look at your sheet and find that text and that's why you are having an issue. In the file you posted where is the list of file names you want to open?

  11. #11
    Registered User
    Join Date
    12-06-2012
    Location
    Richmond, VA
    MS-Off Ver
    Excel 2019
    Posts
    80

    Re: extract range has a missing or illegal field name

    I removed tabs that have data that I'm not using when uploading it here. I see now that Sheet3 and Sheet4 in the attachment below have 'Row Labels.' I don't want to use any data from any tab except that in Sheet1. The files I want to open and consolidate data from are in the same folder and are named 'EmployeeNo_EmployeeLast.xlsx' so, for example, 100093_White.xlsx

    File3.xlsm

  12. #12
    Forum Expert skywriter's Avatar
    Join Date
    06-09-2014
    Location
    USA
    MS-Off Ver
    365 Version 2409
    Posts
    2,789

    Re: extract range has a missing or illegal field name

    I reused some of Jindon's code so hopefully it works the first time.
    If you have any problems copy and paste the line of code that errors, it will be the one highlighted in yellow.
    Try this on a copy.

    Sub ImportWorksheets()
    Dim ws As Worksheet, a, i As Long, myName As String, dic As Object, arrFiles, j, wbSrc As Workbook
    Application.ScreenUpdating = False
        Set dic = CreateObject("Scripting.Dictionary")
          With Sheets("sheet1").Cells(1).CurrentRegion
            a = .Columns("g").Value
            For i = 2 To UBound(a, 1)
                If Not dic.exists(a(i, 1)) Then
                    dic(a(i, 1)) = a(i, 1) & "_" & Split(.Cells(i, 6).Value, ",")(0) & ".xlsx"
                End If
            Next
            arrFiles = dic.items()
            For Each j In arrFiles
                If Dir(ThisWorkbook.Path & "\" & j) <> "" Then
                    Set wbSrc = Workbooks.Open(ThisWorkbook.Path & "\" & j)
                    wbSrc.Worksheets(1).Copy After:=ThisWorkbook.Worksheets(ThisWorkbook.Worksheets.Count)
                    wbSrc.Close
                End If
            Next j
        End With
    Application.ScreenUpdating = True
    End Sub
    Last edited by skywriter; 10-08-2015 at 04:59 PM.

  13. #13
    Registered User
    Join Date
    12-06-2012
    Location
    Richmond, VA
    MS-Off Ver
    Excel 2019
    Posts
    80

    Re: extract range has a missing or illegal field name

    So this didn't have any errors, but it imported the data by creating multiple new tabs, naming them by values from the 'Category' column, even though not always by the correct category. Needless to say, is there a way to tweak it so it imports all of the data into one new tab, so it ends up looking like Sheet1? Thanks for all your help by the way, I really appreciate it.

  14. #14
    Forum Expert skywriter's Avatar
    Join Date
    06-09-2014
    Location
    USA
    MS-Off Ver
    365 Version 2409
    Posts
    2,789

    Re: extract range has a missing or illegal field name

    Jindon's code created new workbooks with one tab each in them. This is simply opening the workbooks by using your sample sheet to create the name of the workbook to look for, opening it and copying the existing tab as is. It's not naming anything, it's pulling in sheet number 1 which already has a name, not making decisions to pull in the wrong category or the right category, just copying in sheet 1. I assume it's the only one since the original code only created one tab.

+ 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. Missing Text In Mail Merged Field
    By adil.master in forum Word Formatting & General
    Replies: 2
    Last Post: 03-10-2014, 08:34 AM
  2. Validation list (with illegal characters in the range list)
    By Elainefish in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 04-04-2013, 04:38 PM
  3. Extract a date from a field and append another field's data
    By Leroy221 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 12-07-2012, 11:35 AM
  4. Error: THE EXTRACT RANGE HAS A MISSING OR ILLEGAL FIELD NAME
    By Min22 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-02-2012, 03:40 PM
  5. Keep getting an Range Missing or Illegal Field name error
    By dwhite30518 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-09-2012, 07:07 PM
  6. Advanced Filtering Extract Range Missing,etc
    By bridges_22 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 02-06-2006, 12:19 PM
  7. [SOLVED] illegal field name using advanced filters after inserting a row
    By tron527 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-23-2005, 11:05 PM
  8. missing or ill egal extract range advanced filter
    By tjtjjtjt in forum Excel General
    Replies: 3
    Last Post: 07-10-2005, 06:05 PM

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