Fill and Sort

kenpcli

Board Regular
Joined
Oct 24, 2017
Messages
129
How do I get it to keep filling in the location number? It breaks after it fills the first site.


47Totals For MEDICARE RR$37,253.00-$15,900.45-$20,182.52$0.00$1,170.03
47Totals For MOLINA$0.00$0.00$0.00$0.00$0.00
47Totals For MULTIPLAN$9,156.00-$4,661.86-$1,026.14$0.00$3,468.00
47Totals For SELF PAY$80,687.75-$38,452.48-$37,242.02$149.40$5,142.65
47Totals For TRICARE$39,590.00-$18,544.17-$12,423.73$921.20$9,543.30
47Totals For UNITED HEALTHCARE$237,266.00-$153,616.60-$65,164.26$1,515.56$20,000.70
47Totals For VETERANS ADMIN$23,748.00-$10,461.24-$10,419.76$0.00$2,867.00
Totals For Albuquerque$3,661,122.75-$1,683,474.79-$1,780,094.21$16,942.84$214,496.59
Bellevue
#N/ATotals For AETNA$504,981.00-$312,837.07-$173,143.99$8,490.26$27,490.20
#N/ATotals For CIGNA$201,832.00-$137,141.51-$43,931.99$546.69$21,305.19
#N/ATotals For COMMERCIAL$314,544.00-$221,865.05-$27,915.65$0.00$64,763.30
#N/ATotals For COMMERCIAL FOUNDATIONS
$11,292.00-$3,000.00$0.00$0.00$8,292.00

<colgroup><col><col><col><col span="2"><col><col></colgroup><tbody>
</tbody>


Sub FillDownLookup()


Dim Ar As Areas
Dim Rng As Range
Dim ValU As Long

With Sheets("Analysis")
Set Ar = .Range("A6:A" & .Range("C" & Rows.Count).End(xlUp).row).SpecialCells(xlBlanks).Areas
For Each Rng In Ar
Rng.Value = Evaluate("VLookup(" & Rng.Offset(-1).Resize(1).Address & ",'LEGEND SITE'!A1:B20, 2, False)")
Next Rng
.Columns(1).Insert
With Columns(2)
.SpecialCells(xlConstants, xlTextValues).EntireRow.Delete
End With
.Sort.SortFields.Clear
.Sort.SortFields.Add Key:=.Range("C6", .Range("C" & Rows.Count).End(xlUp)) _
, SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With .Sort
.SetRange Range("B6:H" & Range("B" & Rows.Count).End(xlUp).row)
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End With
End Sub
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
I think we need a more detailed description of what we are looking at there, and what exactly the issue is.
Can you explain, in plain English, exactly how this is supposed to work?
 
Upvote 0
I think we need a more detailed description of what we are looking at there, and what exactly the issue is.
Can you explain, in plain English, exactly how this is supposed to work?

It looks at the city name above it then looks at the spreadsheet marked site legend to get that city number and fill down until it sees the next city name and so forth.
 
Upvote 0
It looks at the city name above
Where? I do not see city at all in the data you posted.

looks at the spreadsheet marked site legend to get that city number and fill down until it sees the next city name and so forth
How is the data on this Legend Site sheet structured? Maybe post sample of that too.

Remember, while this issue id very familiar to you, it is note for us. All that we have to go on is what you have posted here. The more detail you give, the better the chance of you receiving an answer.
 
Upvote 0
Where? I do not see city at all in the data you posted.


How is the data on this Legend Site sheet structured? Maybe post sample of that too.

Remember, while this issue id very familiar to you, it is note for us. All that we have to go on is what you have posted here. The more detail you give, the better the chance of you receiving an answer.

here is the legend
Albuquerque60
Bellevue30
Bellingham35
Boise40
Chehalis10
Great Falls47
Kennewick20
Lewiston42
Olympia16
Portland18
Silverdale22
Spokane29
Tacoma12
Tualatin19
Vancouver14
Yakima25

<tbody>
</tbody><colgroup><col><col></colgroup>
 
Upvote 0
OK. Thanks.
Try this:
Code:
Sub FillDownLookup()

    Dim Ar As Areas
    Dim cell As Range
    Dim ValU As Long
    Dim lRow As Long
    Dim match As Range
    
'   Find last row in column C with data
    lRow = Cells(Rows.Count, "C").End(xlUp).Row
    
    Application.ScreenUpdating = False

    With Sheets("Analysis")
        For Each cell In Range("A6:A" & lRow)
            If cell.Value = "" Then
                cell.Value = Evaluate("VLookup(" & match.Address & ",'LEGEND SITE'!A1:B20, 2, False)")
            Else
                Set match = cell
            End If
        Next cell
        
        .Columns(1).Insert
        
        With Columns(2)
            .SpecialCells(xlConstants, xlTextValues).EntireRow.Delete
        End With
        
        .Sort.SortFields.Clear
        .Sort.SortFields.Add Key:=.Range("C6", .Range("C" & Rows.Count).End(xlUp)) _
            , SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
        With .Sort
            .SetRange Range("B6:H" & Range("B" & Rows.Count).End(xlUp).Row)
            .Header = xlYes
            .MatchCase = False
            .Orientation = xlTopToBottom
            .SortMethod = xlPinYin
            .Apply
        End With
    End With

    Application.ScreenUpdating = True

End Sub
 
Upvote 0
OK. Thanks.
Try this:
Code:
Sub FillDownLookup()

    Dim Ar As Areas
    Dim cell As Range
    Dim ValU As Long
    Dim lRow As Long
    Dim match As Range
    
'   Find last row in column C with data
    lRow = Cells(Rows.Count, "C").End(xlUp).Row
    
    Application.ScreenUpdating = False

    With Sheets("Analysis")
        For Each cell In Range("A6:A" & lRow)
            If cell.Value = "" Then
                cell.Value = Evaluate("VLookup(" & match.Address & ",'LEGEND SITE'!A1:B20, 2, False)")
            Else
                Set match = cell
            End If
        Next cell
        
        .Columns(1).Insert
        
        With Columns(2)
            .SpecialCells(xlConstants, xlTextValues).EntireRow.Delete
        End With
        
        .Sort.SortFields.Clear
        .Sort.SortFields.Add Key:=.Range("C6", .Range("C" & Rows.Count).End(xlUp)) _
            , SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
        With .Sort
            .SetRange Range("B6:H" & Range("B" & Rows.Count).End(xlUp).Row)
            .Header = xlYes
            .MatchCase = False
            .Orientation = xlTopToBottom
            .SortMethod = xlPinYin
            .Apply
        End With
    End With

    Application.ScreenUpdating = True

End Sub

It errors out on this line:
Dim Ar As Areas
Dim cell As Range
Dim ValU As Long
Dim lRow As Long
Dim match As Range

' Find last row in column C with data
lRow = Cells(Rows.Count, "C").End(xlUp).row

Application.ScreenUpdating = False
With Sheets("Analysis")
For Each cell In Range("A6:A" & lRow)
If cell.Value = "" Then
cell.Value = Evaluate("VLookup(" & match.Address & ",'LEGEND SITE'!A1:B20, 2, False)")
Else
Set match = cell
End If
Next cell

.Columns(1).Insert

With Columns(2)
.SpecialCells(xlConstants, xlTextValues).EntireRow.Delete
End With

.Sort.SortFields.Clear
.Sort.SortFields.Add Key:=.Range("C6", .Range("C" & Rows.Count).End(xlUp)) _
, SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With .Sort
.SetRange Range("B6:H" & Range("B" & Rows.Count).End(xlUp).row)
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End With
Application.ScreenUpdating = True
 
Upvote 0
I just copied it out of your original code. It is not part of the VLOOKUP autofill that I modified.
However, I was able to run the complete code and it worked without issues.

What kind of error message are you getting?
Do you have any hidden, protected, or merged cells?
 
Upvote 0
Should probably be
Code:
With[COLOR=#ff0000] .[/COLOR]Columns(2)
   .SpecialCells(xlConstants, xlTextValues).EntireRow.Delete
End With
note the . in front of columns
 
Upvote 0
note the . in front of columns
Good catch. Interestingly, that was the way it was in the original code, and it works just fine for me without it.
Makes me wonder if something else may be going on, like the range issues I mentioned.
 
Upvote 0

Forum statistics

Threads
1,215,356
Messages
6,124,475
Members
449,164
Latest member
Monchichi

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