VBA Code for Adding Sheeets Based on Column Data

megb75

New Member
Joined
Feb 1, 2022
Messages
1
Office Version
  1. 365
Platform
  1. Windows
Hi there!

I am attempting to manipulate data from a very large sheet that I will be udating on an ongoing basis. I would like to find VBA Code to automatically copy rows from the master sheet to a new sheet, based on the values shown in a given column.
1643739903596.png


I have several comumns of data and, in column G, I have data captured from a dropdown box in JotForm. I would like to create a sheet for every unique entry in this column (i.e., one for Brant, One for Hastings, etc.) and have all entries that have that data in column G move to the new sheet for that Association.

Any suggestions?
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Hi and welcome to MrExcel.
Try this:

VBA Code:
Sub create_worksheets()
  Dim c As Range, sh As Worksheet, ky As Variant
  Set sh = Sheets("Master") 'Update your sheet name
  With CreateObject("scripting.dictionary")
     For Each c In sh.Range("G2", sh.Range("G" & Rows.Count).End(xlUp))
        If c.Value <> "" Then .Item(c.Value) = Empty
     Next c
     For Each ky In .Keys
        sh.Range("A1").AutoFilter Columns("G").Column, ky
        Sheets.Add(, Sheets(Sheets.Count)).Name = ky
        sh.AutoFilter.Range.EntireRow.Copy Range("A1")
     Next ky
  End With
  sh.ShowAllData
End Sub

HOW TO INSTALL MACROs
------------------------------------
If you are new to macros, they are easy to install and use. To install it, simply press ALT+F11 to go into the VB editor and, once there, click Insert/Module on its menu bar, then copy/paste the above code into the code window that just opened up. That's it.... you are done. To use the macro, go back to the worksheet with your data on it and press ALT+F8, select the macro name (create_worksheets) from the list that appears and click the Run button. The macro will execute and perform the action(s) you asked for. If you will need to do this again in this same workbook, and if you are using XL2007 or above, make sure you save your file as an "Excel Macro-Enabled Workbook (*.xlsm) and answer the "do you want to enable macros" question as "Yes" or "OK" (depending on the button label for your version of Excel) the next time you open your workbook.
 
Upvote 0

Forum statistics

Threads
1,224,828
Messages
6,181,201
Members
453,022
Latest member
RobertV1609

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