Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 193
Default VBA code for Extracting Data but order of columns changes all the

I have a standard template with fields (worksheet 1) that I need to populate
data with from another worksheet (worksheet 2). The problem is in worksheet
2 the order of the columns will always be different or sometimes the column
name may not exist. Is there a vba code that will compare the column
headings of worksheet 1 and 2 and if the heading exists in worksheet 2, then
that matching column in worksheet 1 will be populated? There are
approximately 30 columns in worksheet 1 to populate.

any help is much appreciated!!
Thanks.
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3,355
Default VBA code for Extracting Data but order of columns changes all the

I prefer to do this by defining a named range in both workbooks that match
and then no matter which column it's in, you can find the data.

myCol = 0
myCol = myWS.Range("Column1Name").Column

would be how you'd access it.

You could do something like

IF myCol 0 then ...
Populate the second worksheet
end if
--
HTH,
Barb Reinhardt



"Confused" wrote:

I have a standard template with fields (worksheet 1) that I need to populate
data with from another worksheet (worksheet 2). The problem is in worksheet
2 the order of the columns will always be different or sometimes the column
name may not exist. Is there a vba code that will compare the column
headings of worksheet 1 and 2 and if the heading exists in worksheet 2, then
that matching column in worksheet 1 will be populated? There are
approximately 30 columns in worksheet 1 to populate.

any help is much appreciated!!
Thanks.

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 193
Default VBA code for Extracting Data but order of columns changes all

By defining named ranges in both worksheets, you mean named ranges for each
matching columns?

Can you further explain the what you mean by the below:

IF myCol 0 then ...
Populate the second worksheet
end if


What would I put in after the word "then" in the first line?
And do I need to put anything after "end if" or will the code end on that
command?

Thanks for your help!

"Barb Reinhardt" wrote:

I prefer to do this by defining a named range in both workbooks that match
and then no matter which column it's in, you can find the data.

myCol = 0
myCol = myWS.Range("Column1Name").Column

would be how you'd access it.

You could do something like

IF myCol 0 then ...
Populate the second worksheet
end if
--
HTH,
Barb Reinhardt



"Confused" wrote:

I have a standard template with fields (worksheet 1) that I need to populate
data with from another worksheet (worksheet 2). The problem is in worksheet
2 the order of the columns will always be different or sometimes the column
name may not exist. Is there a vba code that will compare the column
headings of worksheet 1 and 2 and if the heading exists in worksheet 2, then
that matching column in worksheet 1 will be populated? There are
approximately 30 columns in worksheet 1 to populate.

any help is much appreciated!!
Thanks.

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 193
Default VBA code for Extracting Data but order of columns changes all

Will this work even if I copy and paste a new file into the worksheet,
therefore the order of the columns will change?

Please let me know if I am not being clear.

"Barb Reinhardt" wrote:

I prefer to do this by defining a named range in both workbooks that match
and then no matter which column it's in, you can find the data.

myCol = 0
myCol = myWS.Range("Column1Name").Column

would be how you'd access it.

You could do something like

IF myCol 0 then ...
Populate the second worksheet
end if
--
HTH,
Barb Reinhardt



"Confused" wrote:

I have a standard template with fields (worksheet 1) that I need to populate
data with from another worksheet (worksheet 2). The problem is in worksheet
2 the order of the columns will always be different or sometimes the column
name may not exist. Is there a vba code that will compare the column
headings of worksheet 1 and 2 and if the heading exists in worksheet 2, then
that matching column in worksheet 1 will be populated? There are
approximately 30 columns in worksheet 1 to populate.

any help is much appreciated!!
Thanks.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Extracting 1st 3-digits of postal code that begin with 0 Pcakes Excel Worksheet Functions 8 June 22nd 06 11:35 PM
extracting data from a spreadsheet by searching on columns Tom New Users to Excel 3 October 24th 05 10:36 PM
Extracting data from two columns Dan Excel Discussion (Misc queries) 4 October 5th 05 04:42 AM
Extracting data from other columns Polar Excel Worksheet Functions 0 February 10th 05 12:07 PM
Formula for Extracting Alphabetic Part of a Product Code ob3ron02 Excel Worksheet Functions 1 October 29th 04 07:05 PM


All times are GMT +1. The time now is 10:20 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"