Create New Sheets Based on Specific Values in a Column with VBA

Tguillaume

New Member
Joined
Aug 2, 2021
Messages
5
Office Version
  1. 365
Platform
  1. Windows
Hi all,

I am trying to use a macro to create multiple new worksheets based on the values in a column of an existing worksheet. There are many posts on this site and others that show me how to create new sheets for each unique value in a column. The trouble that I am having is that I need to specify the specific values for the new sheets I want to create. For example, in the mini-sheet I uploaded I want all rows with "Acute Hospital Utilization" and "Emergency Department Utilization" in column B to be included together in one worksheet and all other rows with any other values in column B to be put in a separate worksheet.

I'm including a link below that shows how to create new sheets for each unique value in a column, in case anyone reading this post would like to see that information:

- VBA - Create new sheet based on cell data

Thanks!
Tguillaume

Sample Data.xlsx
AB
1ClinicMeasure
2Clinic APCP Visit
3Clinic APCP Visit
4Clinic APCP Visit
5Clinic APCP Visit
6Clinic APCP Visit
7Clinic APCP Visit
8Clinic APCP Visit
9Clinic APCP Visit
10Clinic APCP Visit
11Clinic APCP Visit
12Clinic APCP Visit
13Clinic APCP Visit
14Clinic APCP Visit
15Clinic APCP Visit
16Clinic APCP Visit
17Clinic APCP Visit
18Clinic APCP Visit
19Clinic APCP Visit
20Clinic APCP Visit
21Clinic APCP Visit
22Clinic APCP Visit
23Clinic APCP Visit
24Clinic AAcute Hospital Utilization
25Clinic AAcute Hospital Utilization_M
26Clinic AED Utilization - 18 years and above
27Clinic AEmergency Department Utilization
28Clinic BPCP Visit
29Clinic BPCP Visit
30Clinic BPCP Visit
31Clinic BPCP Visit
32Clinic BPCP Visit
33Clinic BPCP Visit
34Clinic BPCP Visit
35Clinic BPCP Visit
36Clinic BPCP Visit
37Clinic BPCP Visit
38Clinic BPCP Visit
39Clinic BPCP Visit
40Clinic BPCP Visit
41Clinic BPCP Visit
42Clinic BPCP Visit
43Clinic BPCP Visit
44Clinic BPCP Visit
45Clinic BPCP Visit
46Clinic BPCP Visit
47Clinic BPCP Visit
48Clinic BPCP Visit
49Clinic BPCP Visit
50Clinic BPCP Visit
51Clinic BPCP Visit
52Clinic BPCP Visit
53Clinic BPCP Visit
54Clinic BPCP Visit
55Clinic BPCP Visit
56Clinic BPCP Visit
57Clinic BPCP Visit
58Clinic BPCP Visit
59Clinic BPCP Visit
60Clinic BPCP Visit
61Clinic BPCP Visit
62Clinic BPCP Visit
63Clinic BPCP Visit
64Clinic BPCP Visit
65Clinic BPCP Visit
66Clinic BPCP Visit
67Clinic BPCP Visit
68Clinic BPCP Visit
69Clinic BPCP Visit
70Clinic BPCP Visit
71Clinic BPCP Visit
72Clinic BPCP Visit
73Clinic BPCP Visit
74Clinic BPCP Visit
75Clinic BPCP Visit
76Clinic BPCP Visit
77Clinic BPCP Visit
78Clinic BPCP Visit
79Clinic BPCP Visit
80Clinic BPCP Visit
81Clinic BPCP Visit
82Clinic BPCP Visit
83Clinic BPCP Visit
84Clinic BPCP Visit
85Clinic BPCP Visit
86Clinic BPCP Visit
87Clinic BPCP Visit
88Clinic BPCP Visit
89Clinic BPCP Visit
90Clinic BPCP Visit
91Clinic BPCP Visit
92Clinic BPCP Visit
93Clinic BPCP Visit
94Clinic BPCP Visit
95Clinic BPCP Visit
96Clinic BPCP Visit
97Clinic BPCP Visit
98Clinic BPCP Visit
99Clinic BPCP Visit
100Clinic BPCP Visit
101Clinic BPCP Visit
102Clinic BPCP Visit
103Clinic BPCP Visit
104Clinic BPCP Visit
105Clinic BPCP Visit
106Clinic BPCP Visit
107Clinic BPCP Visit
108Clinic BPCP Visit
109Clinic BPCP Visit
110Clinic BPCP Visit
111Clinic BPCP Visit
112Clinic BPCP Visit
113Clinic BPCP Visit
114Clinic BPCP Visit
115Clinic BPCP Visit
116Clinic BPCP Visit
117Clinic BPCP Visit
118Clinic BPCP Visit
119Clinic BPCP Visit
120Clinic BPCP Visit
121Clinic BPCP Visit
122Clinic BPCP Visit
123Clinic BPCP Visit
124Clinic BPCP Visit
125Clinic BPCP Visit
126Clinic BPCP Visit
127Clinic BPCP Visit
128Clinic BPCP Visit
129Clinic BPCP Visit
130Clinic BPCP Visit
131Clinic BRisk of Continued Opioid Use - Age 18 to 64
132Clinic CPCP Visit
133Clinic CPCP Visit
134Clinic CPCP Visit
135Clinic CPCP Visit
136Clinic CPCP Visit
137Clinic CPCP Visit
138Clinic CPCP Visit
139Clinic CPCP Visit
140Clinic CPCP Visit
141Clinic CPCP Visit
142Clinic CPCP Visit
143Clinic CPCP Visit
144Clinic CPCP Visit
145Clinic CPCP Visit
146Clinic CPCP Visit
147Clinic CPCP Visit
148Clinic CPCP Visit
149Clinic CPCP Visit
150Clinic CPCP Visit
151Clinic CPCP Visit
152Clinic CPCP Visit
153Clinic CPCP Visit
154Clinic CPCP Visit
155Clinic CPCP Visit
156Clinic CPCP Visit
157Clinic CPCP Visit
158Clinic CPCP Visit
159Clinic CPCP Visit
160Clinic CPCP Visit
161Clinic CPCP Visit
162Clinic CPCP Visit
163Clinic CPCP Visit
164Clinic CPCP Visit
165Clinic CPCP Visit
166Clinic CPCP Visit
167Clinic CPCP Visit
168Clinic CPCP Visit
169Clinic CPCP Visit
170Clinic CPCP Visit
171Clinic CPCP Visit
172Clinic CPCP Visit
173Clinic CPCP Visit
174Clinic CPCP Visit
175Clinic CPCP Visit
176Clinic CPCP Visit
177Clinic CPCP Visit
178Clinic CPCP Visit
179Clinic CPCP Visit
180Clinic CPCP Visit
181Clinic CPCP Visit
182Clinic CPCP Visit
183Clinic CPCP Visit
184Clinic CPCP Visit
185Clinic CPCP Visit
186Clinic CPCP Visit
187Clinic CPCP Visit
188Clinic CPCP Visit
189Clinic CPCP Visit
190Clinic CPCP Visit
191Clinic CPCP Visit
192Clinic CPCP Visit
193Clinic CPCP Visit
194Clinic CPCP Visit
195Clinic CPCP Visit
196Clinic CPCP Visit
197Clinic CPCP Visit
198Clinic CPCP Visit
199Clinic CPCP Visit
200Clinic CPCP Visit
201Clinic CPCP Visit
202Clinic CPCP Visit
203Clinic CPCP Visit
204Clinic CPCP Visit
205Clinic CPCP Visit
206Clinic CPCP Visit
207Clinic CPCP Visit
208Clinic CPCP Visit
209Clinic CPCP Visit
210Clinic CPCP Visit
211Clinic CPCP Visit
212Clinic CPCP Visit
213Clinic CPCP Visit
214Clinic CPCP Visit
215Clinic CPCP Visit
216Clinic CPCP Visit
217Clinic CPCP Visit
218Clinic CPCP Visit
219Clinic CPCP Visit
220Clinic CPCP Visit
221Clinic CPCP Visit
222Clinic CPCP Visit
223Clinic CPCP Visit
224Clinic CPCP Visit
225Clinic CPCP Visit
226Clinic CPCP Visit
227Clinic CPCP Visit
228Clinic CPCP Visit
229Clinic CPCP Visit
230Clinic CPCP Visit
231Clinic CPCP Visit
232Clinic CPCP Visit
233Clinic CPCP Visit
234Clinic CPCP Visit
235Clinic CPCP Visit
236Clinic CPCP Visit
237Clinic CPCP Visit
238Clinic CPCP Visit
239Clinic CPCP Visit
240Clinic CPCP Visit
241Clinic CPCP Visit
242Clinic CPCP Visit
243Clinic CPCP Visit
244Clinic CPCP Visit
245Clinic CPCP Visit
246Clinic CPCP Visit
247Clinic CPCP Visit
248Clinic CPCP Visit
249Clinic CPCP Visit
250Clinic CPCP Visit
251Clinic CPCP Visit
252Clinic CPCP Visit
253Clinic CPCP Visit
254Clinic CPCP Visit
255Clinic CPCP Visit
256Clinic CPCP Visit
257Clinic CPCP Visit
258Clinic CPCP Visit
259Clinic CPCP Visit
260Clinic CPCP Visit
261Clinic CPCP Visit
262Clinic CPCP Visit
263Clinic CPCP Visit
264Clinic CPCP Visit
265Clinic CPCP Visit
266Clinic CPCP Visit
267Clinic CPCP Visit
268Clinic CPCP Visit
269Clinic CPCP Visit
270Clinic CPCP Visit
271Clinic CPCP Visit
272Clinic CPCP Visit
273Clinic CPCP Visit
274Clinic CPCP Visit
275Clinic CPCP Visit
276Clinic CPCP Visit
277Clinic CPCP Visit
278Clinic CPCP Visit
279Clinic CPCP Visit
280Clinic CPCP Visit
281Clinic CPCP Visit
282Clinic CPCP Visit
283Clinic C18 years and above
284Clinic C18 years and above
285Clinic EED Utilization - 18 years and above
286Clinic EEmergency Department Utilization
287Clinic EAcute Hospital Utilization
288Clinic EAcute Hospital Utilization
289Clinic EAcute Hospital Utilization_M
290Clinic EAcute Hospital Utilization_S
291Clinic EED Utilization - 18 years and above
292Clinic EEmergency Department Utilization
293Clinic E18 years and above
294Clinic EControlling High Blood Pressure
295Clinic EBlood Pressure Control (<140/90)
296Clinic EControlling High Blood Pressure
297Clinic EHbA1C Control (<8%)
298Clinic ERetinal Eye Exam
299Clinic EED Utilization - 18 years and above
300Clinic EEmergency Department Utilization
301Clinic EColorectal Cancer Screening
302Clinic EColorectal Cancer Screening
303Clinic EControlling High Blood Pressure
304Clinic EED Utilization - 18 years and above
305Clinic EEmergency Department Utilization
306Clinic EControlling High Blood Pressure
307Clinic EColorectal Cancer Screening
308Clinic EColorectal Cancer Screening
309Clinic EColorectal Cancer Screening
310Clinic EBlood Pressure Control (<140/90)
311Clinic EHbA1C Control (<8%)
312Clinic EKidney Health Evaluation for Patients With Diabetes - Age 65 to 74
313Clinic EControlling High Blood Pressure
314Clinic EBlood Pressure Control (<140/90)
315Clinic EControlling High Blood Pressure
316Clinic EHbA1C Control (<8%)
317Clinic EKidney Health Evaluation for Patients With Diabetes - Age 65 to 74
318Clinic EControlling High Blood Pressure
319Clinic EColorectal Cancer Screening
320Clinic EHbA1C Control (<8%)
321Clinic ERetinal Eye Exam
322Clinic EColorectal Cancer Screening
323Clinic EHbA1C Control (<8%)
324Clinic EKidney Health Evaluation for Patients With Diabetes - Age 18 to 64
325Clinic ERisk of Continued Opioid Use - Age 18 to 64
326Clinic EED Utilization - 18 years and above
327Clinic EED Utilization - 18 years and above
328Clinic EEmergency Department Utilization
329Clinic EEmergency Department Utilization
330Clinic EKidney Health Evaluation for Patients With Diabetes - Age 18 to 64
331Clinic EKidney Health Evaluation for Patients With Diabetes - Age 18 to 64
332Clinic ERetinal Eye Exam
333Clinic EControlling High Blood Pressure
334Clinic EColorectal Cancer Screening
335Clinic EColorectal Cancer Screening
336Clinic EUse of Opioids from Multiple Providers
337Clinic EColorectal Cancer Screening
338Clinic EControlling High Blood Pressure
339Clinic EColorectal Cancer Screening
340Clinic EControlling High Blood Pressure
341Clinic EColorectal Cancer Screening
342Clinic EED Utilization - 18 years and above
343Clinic EEmergency Department Utilization
344Clinic EControlling High Blood Pressure
345Clinic EBlood Pressure Control (<140/90)
346Clinic EColorectal Cancer Screening
347Clinic EControlling High Blood Pressure
348Clinic EHbA1C Control (<8%)
349Clinic EKidney Health Evaluation for Patients With Diabetes - Age 18 to 64
350Clinic ERetinal Eye Exam
351Clinic EUse of Imaging Studies for Low Back Pain
352Clinic EHbA1C Control (<8%)
353Clinic ERetinal Eye Exam
354Clinic EED Utilization - 18 years and above
355Clinic EEmergency Department Utilization
356Clinic EColorectal Cancer Screening
357Clinic EBlood Pressure Control (<140/90)
358Clinic EColorectal Cancer Screening
359Clinic EControlling High Blood Pressure
360Clinic EHbA1C Control (<8%)
361Clinic EKidney Health Evaluation for Patients With Diabetes - Age 18 to 64
362Clinic EHbA1C Control (<8%)
363Clinic EKidney Health Evaluation for Patients With Diabetes - Age 65 to 74
364Clinic ERetinal Eye Exam
365Clinic EControlling High Blood Pressure
366Clinic EColorectal Cancer Screening
367Clinic EControlling High Blood Pressure
368Clinic EColorectal Cancer Screening
369Clinic EControlling High Blood Pressure
370Clinic EColorectal Cancer Screening
371Clinic EControlling High Blood Pressure
372Clinic EAcute Hospital Utilization
373Clinic EAcute Hospital Utilization_S
374Clinic EColorectal Cancer Screening
375Clinic EControlling High Blood Pressure
376Clinic ERisk of Continued Opioid Use - Age 18 to 64
377Clinic EColorectal Cancer Screening
378Clinic EControlling High Blood Pressure
379Clinic EBlood Pressure Control (<140/90)
380Clinic EColorectal Cancer Screening
381Clinic EControlling High Blood Pressure
382Clinic EBlood Pressure Control (<140/90)
383Clinic EColorectal Cancer Screening
384Clinic EControlling High Blood Pressure
385Clinic EKidney Health Evaluation for Patients With Diabetes - Age 18 to 64
386Clinic EBlood Pressure Control (<140/90)
387Clinic EColorectal Cancer Screening
388Clinic EControlling High Blood Pressure
389Clinic EED Utilization - 18 years and above
390Clinic EEmergency Department Utilization
391Clinic EColorectal Cancer Screening
392Clinic EControlling High Blood Pressure
393Clinic EED Utilization - 18 years and above
394Clinic EED Utilization - 18 years and above
395Clinic EEmergency Department Utilization
396Clinic EEmergency Department Utilization
397Clinic EControlling High Blood Pressure
398Clinic EControlling High Blood Pressure
399Clinic EControlling High Blood Pressure
400Clinic EED Utilization - 18 years and above
Sheet1
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Hi !​
I want all rows with "Acute Hospital Utilization" and "Emergency Department Utilization" in column B to be included together in one worksheet and all other rows with any other values in column B to be put in a separate worksheet.
Easy with a filter or better with an advanced filter but as you forgot to mention in which worksheets …​
 
Upvote 0
Hi !​

Easy with a filter or better with an advanced filter but as you forgot to mention in which worksheets …​
Hi Marc!

Thanks so much for responding - I was actually able to figure it out by recording a macro, filtering on values in a column, and then reading the resulting code. I am posting what I used below in case anyone else has this issue! In the code below, you would have to specify your range (mine was A:I) and the field you want to filter on (in my case it was field 6), as well as the workbook name, sheet name, and the criteria.

VBA Code:
wbWorkbookName.Worksheets("Worksheet_Name").Range("A:I").AutoFilter Field:=6, Criteria1:=Array("Criteria 1", _
                                                                                      "Criteria2", _
                                                                                      "Criteria3"), _
                                                                                    
             Operator:=xlFilterValues
 
Upvote 0
Solution

Forum statistics

Threads
1,224,823
Messages
6,181,176
Members
453,021
Latest member
Justyna P

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