The extract range has a miising or invalid field name

HotLanta

Board Regular
Joined
Nov 3, 2005
Messages
176
I borrowed some code that was in a worksheet that the people that came before me created...
I have adapted it to work for me in another situation but I am wanting to modify it.
Basically I have a data collection machine that creates csv files with information. I am wanting to extract information from those csv files and if all of the information is present it works beautifully. I find though that we don't always collect a comment field or description field and that is where I get the error "The extract range has a missing or invalid field name".

So in the below it is looking in the datalist for four fields. If not all four are present, it doesn't work. Can the below be modified to extract a certain field if it is present in the csv and leave it blank if it is not?

Selection.SpecialCells(xlCellTypeLastCell).Select
Ref = ActiveCell.Address
r_num = ActiveCell.Row - 1
ActiveWorkbook.Names.Add Name:="Datalist", RefersToR1C1:= _
Range("A2:" & Ref)

Sheets.Add After:=ActiveSheet
Range("B1").FormulaR1C1 = "Feature"
Range("C1").FormulaR1C1 = "Description"
Range("D1").FormulaR1C1 = "Type"
Range("E1").FormulaR1C1 = "Comment"

Range("Datalist").AdvancedFilter Action:=xlFilterCopy, CopyToRange:=Range( _
"B1:E1"), Unique:=False
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
How about
Code:
Sub HotLanta()
    Dim Ary As Variant
    Dim i As Long, j As Long
    Dim Ws As Worksheet
    Dim Fnd As Range
    
    Set Ws = ActiveSheet
    Ary = Array("Feature", "Description", "Type", "Comment")

    Ref = Ws.Range("A1").SpecialCells(xlLastCell).Address
    ActiveWorkbook.Names.Add Name:="Datalist", RefersToR1C1:=Range("A2:" & Ref)
    
    Sheets.Add After:=ActiveSheet
    For i = 0 To UBound(Ary)
        Set Fnd = Ws.Range("2:2").Find(Ary(i), , , xlWhole, , , False, , False)
        If Not Fnd Is Nothing Then j = j + 1: Cells(1, j + 1) = Ary(i)
    Next i

    Range("Datalist").AdvancedFilter Action:=xlFilterCopy, CopyToRange:=Range("B1", Cells(1, j + 1)), Unique:=False
End Sub
 
Upvote 0
You could simply run 4 advanced filters within an On Error Resume Next, each extracting one column.
 
Upvote 0

Forum statistics

Threads
1,224,746
Messages
6,180,703
Members
452,994
Latest member
Janick

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