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

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
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,223,707
Messages
6,174,000
Members
452,542
Latest member
Bricklin

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