Search : in
By :

Excel Macro - Dynamic Column Selection

Last answer on Mar 24, 2009 4:42:23 pm GMT kunalp, on Dec 10, 2008 3:59:32 am GMT 
 Report this message to moderators

Hello,

I am just beginning to learn Excel macros. I was working on a sheet wherein I have to select a column dynamically, based on just the column header name. Let me explain.

Say there is an Excel Sheet which contains the following columns (from A1 to D1):

RecNo Cust_ID Cust_Name Contact_Num

Below these, there is customer data which is present. Now, I want to extract just the Cust_ID (from Column B) and Cust_Name (from Column C) for all the records.

However, the problem is that it is not necessary that Cust_ID would always be in Column B. Though the heading would always be Cust_ID, its location could change to Column C in some other sheet that has been generated and Cust_Name could instead have been present in Column B (the two columns that need to be extracted have been interchanged).

Using the match function, I am able to determine the position of the column, but after that I am not able to select that column. The function I have used to determine the column number is given below:

WorksheetFunction.Match("Cust_ID", Range("A1:D1"), 0)

Can someone please help?

Configuration: Windows XP
Internet Explorer 7.0

Best answers for « Excel Macro Dynamic Column Selection » in :
Excel – Macro to detect and hide blank rows ShowExcel – Macro to detect and hide blank rows Issue Solution Note Issue I want a macro to unhide about 20 blank rows copy values into the top row then hide the remaining rows (some cells have fill though) then the next time it will...
Excel – Macro for copy & paste selected range ShowExcel – Macro for copy & paste selected range Issue Solution Note Issue I have a summary of data by month in one sheet and the raw data in another sheet. Instead of creating multiple worksheets for my raw data for each month, I want...
Excel – Comparing cell A1 to entire A column in Sheet 2 ShowExcel – Comparing cell A1 to entire A column in Sheet 2 Issue Solution Note Issue I have been trying to compare sheet1 A2 to sheet2 A2 through A500 and if it exists somewhere in sheet2's a col then copy that entire row to a new sheet....

1

 Pankaj, on Mar 24, 2009 4:42:23 pm GMT
  • +10

I have created something like this.

Consider this:

The last row of the spreadsheet should have values 1 & 0. make a sweep through the bottom row, select all 1s and hide all 0s.

If you need more help on code, reply.

Reply to Pankaj