VBA to delete columns from a given list

Prince27

New Member
Joined
Nov 24, 2012
Messages
41
Hello Experts,

I'm looking for a VBA to delete columns based on header name.

There are 2 tabs(sheets) "Main Data" and "Columns" respectively.

Columns tab has the list of column names which I need to use for reporting purpose. "Main Data" tab is a dump or raw data which has huge data set. Attached is the image for your reference.

Here i'm looking for VB code to delete columns which are available as a list Columns tab and delete the rest of the columns.

I want the VB code to be dynamic, so that End user can add or delete or modify the list in Columns tab.
 

Attachments

  • Main Data.JPG
    Main Data.JPG
    66.5 KB · Views: 71
  • Columns Needed.JPG
    Columns Needed.JPG
    35.4 KB · Views: 68
Last edited:

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Hello Experts,

I have another requirement as below :

There are 2 tabs Main Data & Mail Info

1. In Main Data tab I have around 50 columns, 1 of the column name is "EMail" which has different names.
2. In Mail Info tab, I have a list of Unique names in column A (A2:A20) and cell C7 has a drop down list with unique names (referring to column A2:A20)

Requirement 1 : I need a code if cell C7 of Mail Info tab = ALL, then data in the Main Data tab to be filtered with each unique name under column 'Email' and save as a new workbook (only with respective unique name's data) and create a new folder with unique name and save the workbook in the folder in a given path say (Path: "C:\My Documents\"). If folder already exists with the unique name in the path, then only workbook has to be saved.

Requirement 2 : If cell C7 of Mail info tab = "Bob", then only this respective name's data in Main Data tab to be filtered and save as new workbook in the respective folder of the given path like above.

Appreciate your help in advance.
 
Upvote 0
I suggest you post that as a new query because it has nothing to do with deleting columns, and you get more people looking at it because, this thread has got to page 2 and lots people won't be looking at it. Before you do that, I suggest you try and write it with a bit more detail and less ambiguity.:
1 of the column name is "EMail" which has different names. What does this mean??
then data in the Main Data tab to be filtered with each unique name under column 'Email' and save as a new workbook (only with respective unique name's data) and create a new folder with unique name and save the workbook in the folder in a given path say (Path: "C:\My Documents\"). If folder already exists with the unique name in the path, then only workbook has to be saved.
Write this out in more detail because it is not clear what you want. Is "ALL"" in the list of names in the EMAil column, When you say filter with each unique name, do you mean this should be done in a loop so that it is done 18 times, and 18 different workbooks are created? Is it just the Main Data tab that you want in each of these New workbooks or do you want all the tabs in the current workbook as well. Do you want the whole Main data worksheet or do you just want the filtered data? Do you need to copy any formatting across from the MAin data worksheet, or is Values good enough
 
Upvote 0
Sure as you suggest i will post it as a new query. Below is the requirement for your reference:


Lets say there are 2 different workbooks :

1 is Raw data workbook with only 1 tab or worksheet called Main Data

1 more workbook where i have or want the code and has only 1 worksheet named Mail Info



Requirement 1 :

In Mail Info workbook Column A ( A2:A50) i have a list of names like Bob, Jack, John, Sibu etc and Cell C7 has a drop down list with reference to column A (A2:A50)



In Raw data file, say i have columns Plan A, Plan B, Email, Plan C, Notes etc., Column Email has different names ( Bob, Jack, John etc)



In Mail Info file, Cell value C7 says Bob, then data related to Bob in the Raw data should be filtered along with formatting (as few of the cells will be colored) and should create a new folder called Bob ( with value in cell C7) and save as a new workbook ( raw data file has only 1 worksheet/tab) in that folder. If folder already exists only file should be saved in the respective folder.



Requirement 2:



In Mail Info file, cell value C7 says ALL, then what ever unique names available under Column Email of the Raw data file ( say there are 10 unique names) data to be filtered for all the unique names accordingly and 10 unique files and folders to created and saved accordingly.



Save as each file or workbook with unique name given under email column



Hope this time i am much clearer.



Apologies for not able to share the sample file.



Thank you so much for the support.
 
Upvote 0

Forum statistics

Threads
1,215,837
Messages
6,127,185
Members
449,368
Latest member
JayHo

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