Copy sheet and add Location number

kenpcli

Board Regular
Joined
Oct 24, 2017
Messages
129
I am trying get a macro to look down column A and each change in site name add their location number underneath it.

Chg AmtPay AmtAdj AmtRef AmtBal Amt
Albuquerque
60Totals For AETNA$51,896.00-$31,204.59-$19,152.69$164.35$1,703.07
60Totals For BCBS$659,678.00-$320,482.96-$324,294.18$7,687.05$22,587.91
60Totals For CIGNA$264.00-$211.20-$52.80$0.00$0.00
60Totals For COMMERCIAL$20,122.00-$13,354.59-$4,563.70$0.00$2,203.71
60Totals For DSHS$8,573.00-$4,020.36-$60.64$0.00$4,492.00
60Totals For FCHN$3,774.00-$2,868.21-$905.79$0.00$0.00
60Totals For HUMANA$309.00-$167.12-$141.88$0.00$0.00
60Totals For IPN$3,923.00-$2,678.76-$1,244.24$0.00$0.00
60Totals For MEDICAID COMMERCIAL$115,651.00-$41,467.85-$57,352.41$498.51$17,329.25
60Totals For MEDICARE$1,928,300.00-$849,877.14-$1,015,188.85$3,064.69$66,298.70
60Totals For MEDICARE ADVANTAGE$440,932.00-$175,505.21-$210,678.60$2,942.08$57,690.27
60Totals For MEDICARE RR$37,253.00-$15,900.45-$20,182.52$0.00$1,170.03
60Totals For MOLINA$0.00$0.00$0.00$0.00$0.00
60Totals For MULTIPLAN$9,156.00-$4,661.86-$1,026.14$0.00$3,468.00
60Totals For SELF PAY$80,687.75-$38,452.48-$37,242.02$149.40$5,142.65
60Totals For TRICARE$39,590.00-$18,544.17-$12,423.73$921.20$9,543.30
60Totals For UNITED HEALTHCARE$237,266.00-$153,616.60-$65,164.26$1,515.56$20,000.70
60Totals 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
30Totals For AETNA$504,981.00-$312,837.07-$173,143.99$8,490.26$27,490.20
30Totals For CIGNA$201,832.00-$137,141.51-$43,931.99$546.69$21,305.19

<colgroup><col><col><col><col span="2"><col><col></colgroup><tbody>
</tbody>
 
In that case how about
Code:
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:B1000, 2, False)")
        Next Rng
    End With
    
End Sub

Thank you I will try this and let you know how it works.
 
Upvote 0

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Thank you I will try this and let you know how it works.

This is what I get when it runs: The site number is not correct and it stops after the first location.

Albuquerque
47Totals For AETNA$51,896.00-$31,204.59-$19,152.69$164.35$1,703.07
47Totals For BCBS$659,678.00-$320,482.96-$324,294.18$7,687.05$22,587.91
47Totals For CIGNA$264.00-$211.20-$52.80$0.00$0.00
47Totals For COMMERCIAL$20,122.00-$13,354.59-$4,563.70$0.00$2,203.71
47Totals For DSHS$8,573.00-$4,020.36-$60.64$0.00$4,492.00
47Totals For FCHN$3,774.00-$2,868.21-$905.79$0.00$0.00
47Totals For HUMANA$309.00-$167.12-$141.88$0.00$0.00
47Totals For IPN$3,923.00-$2,678.76-$1,244.24$0.00$0.00
47Totals For MEDICAID COMMERCIAL$115,651.00-$41,467.85-$57,352.41$498.51$17,329.25
47Totals For MEDICARE$1,928,300.00-$849,877.14-$1,015,188.85$3,064.69$66,298.70
47Totals For MEDICARE ADVANTAGE$440,932.00-$175,505.21-$210,678.60$2,942.08$57,690.27
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
#N/ATotals For CONTRACTED COMMERCIAL$454.00-$241.25-$129.29$0.00$83.46
#N/ATotals For COORDINATED CARE$216,179.00-$93,977.41-$111,775.06$600.01$11,026.54
#N/ATotals For DSHS$70,023.00-$21,523.32-$38,280.68$0.00$10,219.00
#N/ATotals For FCHN$195,657.00-$139,056.11-$42,719.61$1,304.50$15,185.78
#N/ATotals For IPN$55.00-$20.41-$34.59$0.00$0.00

<tbody>
</tbody><colgroup><col><col><col><col span="2"><col><col></colgroup>
 
Upvote 0
This is what I get

Excel 2013 32 bit
AB
1SiteNo
2Albuquerque60
3Bellevue30
4Bellingham35
5Boise40
6Chehalis10
7Great Falls47
8Kennewick20
9Lewiston42
10Olympia16
11Portland18
12Silverdale22
13Spokane29
14Tacoma12
15Tualatin19
16Vancouver14
17Yakima25
Legend site




Excel 2013 32 bit
ABCDEFG
1Pacific Cataract And Laser Institute
2PCLI CONTRACTUAL YTD BY SITE
3From 1/1/2017 to 9/30/2017
410/16/2017 12:04 PM
5Chg AmtPay AmtAdj AmtRef AmtBal Amt
6Albuquerque
760Totals For AETNA$51,896.00-$31,204.59-$19,152.69$164.35$1,703.07
860Totals For BCBS$659,678.00-$320,482.96-$324,294.18$7,687.05$22,587.91
25Totals For Albuquerque$3,661,122.75-$1,683,474.79-$1,780,094.21$16,942.84$214,496.59
26Bellevue
2730Totals For AETNA$504,981.00-$312,837.07-$173,143.99$8,490.26$27,490.20
2830Totals For CIGNA$201,832.00-$137,141.51-$43,931.99$546.69$21,305.19
4930Totals For UNITED HEALTHCARE$235,518.00-$161,307.83-$60,194.42$2,498.52$16,514.27
50Totals For Bellevue$10,791,128.00-$6,031,247.18-$4,342,203.21$42,962.36$460,639.97
51Spokane
5229Totals For AETNA$51,896.00-$31,204.59-$19,152.69$164.35$1,703.07
5329Totals For BCBS$659,678.00-$320,482.96-$324,294.18$7,687.05$22,587.91
6929Totals For VETERANS ADMIN$23,748.00-$10,461.24-$10,419.76$0.00$2,867.00
70Totals For Spokane$3,661,122.75-$1,683,474.79-$1,780,094.21$16,942.84$214,496.59
71Great Falls
7247Totals For AETNA$504,981.00-$312,837.07-$173,143.99$8,490.26$27,490.20
9447Totals For UNITED HEALTHCARE$235,518.00-$161,307.83-$60,194.42$2,498.52$16,514.27
95Totals For Great Falls$10,791,128.00-$6,031,247.18-$4,342,203.21$42,962.36$460,639.97
Analysis
 
Upvote 0
This is what I get
Excel 2013 32 bit
AB
1SiteNo
2Albuquerque60
3Bellevue30
4Bellingham35
5Boise40
6Chehalis10
7Great Falls47
8Kennewick20
9Lewiston42
10Olympia16
11Portland18
12Silverdale22
13Spokane29
14Tacoma12
15Tualatin19
16Vancouver14
17Yakima25

<colgroup><col><col><col></colgroup><thead>
</thead><tbody>
</tbody>
Legend site




Excel 2013 32 bit
ABCDEFG
1Pacific Cataract And Laser Institute
2PCLI CONTRACTUAL YTD BY SITE
3From 1/1/2017 to 9/30/2017
410/16/2017 12:04 PM
5Chg AmtPay AmtAdj AmtRef AmtBal Amt
6Albuquerque
760Totals For AETNA$51,896.00-$31,204.59-$19,152.69$164.35$1,703.07
860Totals For BCBS$659,678.00-$320,482.96-$324,294.18$7,687.05$22,587.91
25Totals For Albuquerque$3,661,122.75-$1,683,474.79-$1,780,094.21$16,942.84$214,496.59
26Bellevue
2730Totals For AETNA$504,981.00-$312,837.07-$173,143.99$8,490.26$27,490.20
2830Totals For CIGNA$201,832.00-$137,141.51-$43,931.99$546.69$21,305.19
4930Totals For UNITED HEALTHCARE$235,518.00-$161,307.83-$60,194.42$2,498.52$16,514.27
50Totals For Bellevue$10,791,128.00-$6,031,247.18-$4,342,203.21$42,962.36$460,639.97
51Spokane
5229Totals For AETNA$51,896.00-$31,204.59-$19,152.69$164.35$1,703.07
5329Totals For BCBS$659,678.00-$320,482.96-$324,294.18$7,687.05$22,587.91
6929Totals For VETERANS ADMIN$23,748.00-$10,461.24-$10,419.76$0.00$2,867.00
70Totals For Spokane$3,661,122.75-$1,683,474.79-$1,780,094.21$16,942.84$214,496.59
71Great Falls
7247Totals For AETNA$504,981.00-$312,837.07-$173,143.99$8,490.26$27,490.20
9447Totals For UNITED HEALTHCARE$235,518.00-$161,307.83-$60,194.42$2,498.52$16,514.27
95Totals For Great Falls$10,791,128.00-$6,031,247.18-$4,342,203.21$42,962.36$460,639.97

<colgroup><col><col><col><col><col><col><col><col></colgroup><thead>
</thead><tbody>
</tbody>
Analysis

ok if I try it as a stand alone it works, but if I add it to the already existing code, it breaks.

Sub MergeWorkbooks()
Dim FolderName As String
Dim directory As String, fileName As String
Dim wb1 As Workbook, wb2 As Workbook
Dim ws As Worksheet
Set wb1 = Workbooks.Add

With Application.FileDialog(msoFileDialogFolderPicker)
.Title = "Please select a folder."
.AllowMultiSelect = False
.Show
On Error Resume Next
FolderName = .SelectedItems(1)
Err.Clear
On Error GoTo 0
End With
directory = FolderName & ""
fileName = Dir(directory & "*.xls?")
Do While fileName <> ""
Set wb2 = Workbooks.Open(directory & fileName)
For Each ws In wb2.Sheets
ws.Copy After:=wb1.Sheets(wb1.Sheets.Count)
Next ws
wb2.Close savechanges:=False
fileName = Dir
Loop
'Stopping Application Alerts
Application.DisplayAlerts = False
Sheets("Sheet1").Delete
'Enabling Application alerts once we are done with our task
Application.DisplayAlerts = True
Sheets("Page 1 (3)").Name = "Analysis"
Sheets("Page 1 (4)").Name = "PCLI TB"
Sheets("Page 1 (2)").Name = "Charges Posted After"
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:B1000, 2, False)")
Next Rng
End With
End Sub
 
Upvote 0
Do you have a sheet in that workbook called Legend Site?
 
Upvote 0
There's nothing I can see in your code that would cause a problem.
But as the code I supplied works on its own & because I can't see your files, or sheets there's not much more I can do to help.
 
Upvote 0
There's nothing I can see in your code that would cause a problem.
But as the code I supplied works on its own & because I can't see your files, or sheets there's not much more I can do to help.

I understand, thank you. I broke it into two macros and it works fine.
 
Upvote 0
I think it broke again, now when I run it, it doesn't like

Set Ar = .Range("A6:A" & .Range("C" & rows.Count).End(xlUp).row).SpecialCells(xlBlanks).Areas

any ideas?
 
Upvote 0
Are some of the files .xls & some newer versions such as .xlsx or .xlsm?
 
Upvote 0

Similar threads

Forum statistics

Threads
1,214,901
Messages
6,122,157
Members
449,068
Latest member
shiz11713

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