Moving Data Between Sheets Based on Columns

Michael151

Board Regular
Joined
Sep 20, 2010
Messages
247
Hello all,

Need help writing a macro that will move data in one specific column and row to another sheet based on the header in row 1.

The columns that need to be moved are:

Library

Deal_Date
Title

This is sheet 1:

<table border="0" cellpadding="0" cellspacing="0" width="348"><col style="width: 48pt;" width="64" span="2"> <col style="width: 69pt;" width="92"> <col style="width: 48pt;" width="64" span="2"> <tbody><tr style="height: 12.75pt;" height="17"> <td class="xl25" style="height: 12.75pt; width: 48pt;" align="right" width="64" height="17">1</td> <td class="xl26" style="border-left: medium none; width: 48pt;" width="64">library</td> <td class="xl26" style="border-left: medium none; width: 69pt;" width="92">Deal_Date</td> <td class="xl26" style="border-left: medium none; width: 48pt;" width="64">
</td> <td class="xl26" style="border-left: medium none; width: 48pt;" width="64">Title</td> </tr> <tr style="height: 12.75pt;" height="17"> <td class="xl25" style="height: 12.75pt; border-top: medium none;" align="right" height="17">2</td> <td class="xl27" style="border-top: medium none; border-left: medium none; width: 48pt;" width="64">W</td> <td class="xl28" style="border-top: medium none; border-left: medium none; width: 69pt;" width="92">01-Jan-11</td> <td class="xl27" style="border-top: medium none; border-left: medium none; width: 48pt;" align="right" width="64">2</td> <td class="xl27" style="border-top: medium none; border-left: medium none; width: 48pt;" width="64">Title1</td> </tr> <tr style="height: 12.75pt;" height="17"> <td class="xl25" style="height: 12.75pt; border-top: medium none;" align="right" height="17">3</td> <td class="xl27" style="border-top: medium none; border-left: medium none; width: 48pt;" width="64">W</td> <td class="xl28" style="border-top: medium none; border-left: medium none; width: 69pt;" width="92">01-Jan-11</td> <td class="xl27" style="border-top: medium none; border-left: medium none; width: 48pt;" align="right" width="64">2</td> <td class="xl27" style="border-top: medium none; border-left: medium none; width: 48pt;" width="64">Title1</td> </tr> <tr style="height: 12.75pt;" height="17"> <td class="xl25" style="height: 12.75pt; border-top: medium none;" align="right" height="17">4</td> <td class="xl27" style="border-top: medium none; border-left: medium none; width: 48pt;" width="64">W</td> <td class="xl28" style="border-top: medium none; border-left: medium none; width: 69pt;" width="92">01-Jan-11</td> <td class="xl27" style="border-top: medium none; border-left: medium none; width: 48pt;" align="right" width="64">2</td> <td class="xl27" style="border-top: medium none; border-left: medium none; width: 48pt;" width="64">Title1</td> </tr> <tr style="height: 12.75pt;" height="17"> <td class="xl25" style="height: 12.75pt; border-top: medium none;" align="right" height="17">5</td> <td class="xl27" style="border-top: medium none; border-left: medium none; width: 48pt;" width="64">W</td> <td class="xl28" style="border-top: medium none; border-left: medium none; width: 69pt;" width="92">01-Jan-11</td> <td class="xl27" style="border-top: medium none; border-left: medium none; width: 48pt;" align="right" width="64">2</td> <td class="xl27" style="border-top: medium none; border-left: medium none; width: 48pt;" width="64">Title1</td> </tr> <tr style="height: 12.75pt;" height="17"> <td class="xl25" style="height: 12.75pt; border-top: medium none;" align="right" height="17">6</td> <td class="xl27" style="border-top: medium none; border-left: medium none; width: 48pt;" width="64">W</td> <td class="xl28" style="border-top: medium none; border-left: medium none; width: 69pt;" width="92">01-Jan-11</td> <td class="xl27" style="border-top: medium none; border-left: medium none; width: 48pt;" align="right" width="64">2</td> <td class="xl27" style="border-top: medium none; border-left: medium none; width: 48pt;" width="64">Title1</td> </tr> <tr style="height: 12.75pt;" height="17"> <td class="xl25" style="height: 12.75pt; border-top: medium none;" align="right" height="17">7</td> <td class="xl27" style="border-top: medium none; border-left: medium none; width: 48pt;" width="64">W</td> <td class="xl28" style="border-top: medium none; border-left: medium none; width: 69pt;" width="92">01-Jan-11</td> <td class="xl27" style="border-top: medium none; border-left: medium none; width: 48pt;" align="right" width="64">2</td> <td class="xl27" style="border-top: medium none; border-left: medium none; width: 48pt;" width="64">Title1</td> </tr> <tr style="height: 12.75pt;" height="17"> <td class="xl25" style="height: 12.75pt; border-top: medium none;" align="right" height="17">8</td> <td class="xl27" style="border-top: medium none; border-left: medium none; width: 48pt;" width="64">W</td> <td class="xl28" style="border-top: medium none; border-left: medium none; width: 69pt;" width="92">01-Jan-11</td> <td class="xl27" style="border-top: medium none; border-left: medium none; width: 48pt;" align="right" width="64">2</td> <td class="xl27" style="border-top: medium none; border-left: medium none; width: 48pt;" width="64">Title1</td> </tr> <tr style="height: 12.75pt;" height="17"> <td class="xl25" style="height: 12.75pt; border-top: medium none;" align="right" height="17">9</td> <td class="xl27" style="border-top: medium none; border-left: medium none; width: 48pt;" width="64">W</td> <td class="xl28" style="border-top: medium none; border-left: medium none; width: 69pt;" width="92">01-Jan-11</td> <td class="xl27" style="border-top: medium none; border-left: medium none; width: 48pt;" align="right" width="64">2</td> <td class="xl27" style="border-top: medium none; border-left: medium none; width: 48pt;" width="64">Title1</td> </tr> <tr style="height: 12.75pt;" height="17"> <td class="xl25" style="height: 12.75pt; border-top: medium none;" align="right" height="17">10</td> <td class="xl27" style="border-top: medium none; border-left: medium none; width: 48pt;" width="64">W</td> <td class="xl28" style="border-top: medium none; border-left: medium none; width: 69pt;" width="92">01-Jan-11</td> <td class="xl27" style="border-top: medium none; border-left: medium none; width: 48pt;" align="right" width="64">2</td> <td class="xl27" style="border-top: medium none; border-left: medium none; width: 48pt;" width="64">Title1</td> </tr> <tr style="height: 12.75pt;" height="17"> <td class="xl25" style="height: 12.75pt; border-top: medium none;" align="right" height="17">11</td> <td class="xl27" style="border-top: medium none; border-left: medium none; width: 48pt;" width="64">W</td> <td class="xl28" style="border-top: medium none; border-left: medium none; width: 69pt;" width="92">01-Jan-11</td> <td class="xl27" style="border-top: medium none; border-left: medium none; width: 48pt;" align="right" width="64">2</td> <td class="xl27" style="border-top: medium none; border-left: medium none; width: 48pt;" width="64">Title1</td> </tr> </tbody></table>
This is sheet2:

<table border="0" cellpadding="0" cellspacing="0" width="284"><col style="width: 48pt;" width="64" span="2"> <col style="width: 69pt;" width="92"> <col style="width: 48pt;" width="64"> <tbody><tr style="height: 12.75pt;" height="17"> <td class="xl27" style="height: 12.75pt; width: 48pt;" align="right" width="64" height="17">1</td> <td class="xl28" style="border-left: medium none; width: 48pt;" width="64">library</td> <td class="xl28" style="border-left: medium none; width: 69pt;" width="92">Deal_Date</td> <td class="xl28" style="border-left: medium none; width: 48pt;" width="64">Title</td> </tr> <tr style="height: 25.5pt;" height="34"> <td class="xl27" style="height: 25.5pt; border-top: medium none;" align="right" height="34">2</td> <td class="xl29" style="border-top: medium none; border-left: medium none; width: 48pt;" width="64">L</td> <td class="xl30" style="border-top: medium none; border-left: medium none; width: 69pt;" width="92">01-Feb-11</td> <td class="xl29" style="border-top: medium none; border-left: medium none; width: 48pt;" width="64">Title2</td> </tr> <tr style="height: 25.5pt;" height="34"> <td class="xl27" style="height: 25.5pt; border-top: medium none;" align="right" height="34">3</td> <td class="xl29" style="border-top: medium none; border-left: medium none; width: 48pt;" width="64">L</td> <td class="xl30" style="border-top: medium none; border-left: medium none; width: 69pt;" width="92">02-Feb-11</td> <td class="xl29" style="border-top: medium none; border-left: medium none; width: 48pt;" width="64">Title3</td> </tr> <tr style="height: 25.5pt;" height="34"> <td class="xl27" style="height: 25.5pt; border-top: medium none;" align="right" height="34">4</td> <td class="xl29" style="border-top: medium none; border-left: medium none; width: 48pt;" width="64">L</td> <td class="xl30" style="border-top: medium none; border-left: medium none; width: 69pt;" width="92">03-Feb-11</td> <td class="xl29" style="border-top: medium none; border-left: medium none; width: 48pt;" width="64">Title4</td> </tr> <tr style="height: 25.5pt;" height="34"> <td class="xl27" style="height: 25.5pt; border-top: medium none;" align="right" height="34">5</td> <td class="xl29" style="border-top: medium none; border-left: medium none; width: 48pt;" width="64">L</td> <td class="xl30" style="border-top: medium none; border-left: medium none; width: 69pt;" width="92">04-Feb-11</td> <td class="xl29" style="border-top: medium none; border-left: medium none; width: 48pt;" width="64">Title5</td> </tr> <tr style="height: 25.5pt;" height="34"> <td class="xl27" style="height: 25.5pt; border-top: medium none;" align="right" height="34">6</td> <td class="xl29" style="border-top: medium none; border-left: medium none; width: 48pt;" width="64">L</td> <td class="xl30" style="border-top: medium none; border-left: medium none; width: 69pt;" width="92">
</td> <td class="xl29" style="border-top: medium none; border-left: medium none; width: 48pt;" width="64">
</td> </tr> <tr style="height: 25.5pt;" height="34"> <td class="xl27" style="height: 25.5pt; border-top: medium none;" align="right" height="34">7</td> <td class="xl29" style="border-top: medium none; border-left: medium none; width: 48pt;" width="64">L</td> <td class="xl30" style="border-top: medium none; border-left: medium none; width: 69pt;" width="92">06-Feb-11</td> <td class="xl29" style="border-top: medium none; border-left: medium none; width: 48pt;" width="64">Title7</td> </tr> <tr style="height: 25.5pt;" height="34"> <td class="xl27" style="height: 25.5pt; border-top: medium none;" align="right" height="34">8</td> <td class="xl29" style="border-top: medium none; border-left: medium none; width: 48pt;" width="64">L</td> <td class="xl30" style="border-top: medium none; border-left: medium none; width: 69pt;" width="92">07-Feb-11</td> <td class="xl29" style="border-top: medium none; border-left: medium none; width: 48pt;" width="64">Title8</td> </tr> <tr style="height: 25.5pt;" height="34"> <td class="xl27" style="height: 25.5pt; border-top: medium none;" align="right" height="34">9</td> <td class="xl29" style="border-top: medium none; border-left: medium none; width: 48pt;" width="64">L</td> <td class="xl30" style="border-top: medium none; border-left: medium none; width: 69pt;" width="92">08-Feb-11</td> <td class="xl29" style="border-top: medium none; border-left: medium none; width: 48pt;" width="64">Title9</td> </tr> </tbody></table>

At the end of sheet 1 (row 11 in this case), I need to move the data in sheet 2 into sheet 1, keeping the data across each row just as it is in sheet 2.

After running the macro, the sheet will look like this:

<table border="0" cellpadding="0" cellspacing="0" width="284"><col style="width: 48pt;" width="64" span="2"> <col style="width: 69pt;" width="92"> <col style="width: 48pt;" width="64"> <tbody><tr style="height: 12.75pt;" height="17"> <td class="xl27" style="height: 12.75pt; width: 48pt;" align="right" width="64" height="17">1</td> <td class="xl28" style="border-left: medium none; width: 48pt;" width="64">library</td> <td class="xl28" style="border-left: medium none; width: 69pt;" width="92">Deal_Date</td> <td class="xl28" style="border-left: medium none; width: 48pt;" width="64">Title</td> </tr> <tr style="height: 12.75pt;" height="17"> <td class="xl27" style="height: 12.75pt; border-top: medium none;" align="right" height="17">2</td> <td class="xl29" style="border-top: medium none; border-left: medium none; width: 48pt;" width="64">W</td> <td class="xl30" style="border-top: medium none; border-left: medium none; width: 69pt;" width="92">01-Jan-11</td> <td class="xl29" style="border-top: medium none; border-left: medium none; width: 48pt;" width="64">Title1</td> </tr> <tr style="height: 12.75pt;" height="17"> <td class="xl27" style="height: 12.75pt; border-top: medium none;" align="right" height="17">3</td> <td class="xl29" style="border-top: medium none; border-left: medium none; width: 48pt;" width="64">W</td> <td class="xl30" style="border-top: medium none; border-left: medium none; width: 69pt;" width="92">01-Jan-11</td> <td class="xl29" style="border-top: medium none; border-left: medium none; width: 48pt;" width="64">Title1</td> </tr> <tr style="height: 12.75pt;" height="17"> <td class="xl27" style="height: 12.75pt; border-top: medium none;" align="right" height="17">4</td> <td class="xl29" style="border-top: medium none; border-left: medium none; width: 48pt;" width="64">W</td> <td class="xl30" style="border-top: medium none; border-left: medium none; width: 69pt;" width="92">01-Jan-11</td> <td class="xl29" style="border-top: medium none; border-left: medium none; width: 48pt;" width="64">Title1</td> </tr> <tr style="height: 12.75pt;" height="17"> <td class="xl27" style="height: 12.75pt; border-top: medium none;" align="right" height="17">5</td> <td class="xl29" style="border-top: medium none; border-left: medium none; width: 48pt;" width="64">W</td> <td class="xl30" style="border-top: medium none; border-left: medium none; width: 69pt;" width="92">01-Jan-11</td> <td class="xl29" style="border-top: medium none; border-left: medium none; width: 48pt;" width="64">Title1</td> </tr> <tr style="height: 12.75pt;" height="17"> <td class="xl27" style="height: 12.75pt; border-top: medium none;" align="right" height="17">6</td> <td class="xl29" style="border-top: medium none; border-left: medium none; width: 48pt;" width="64">W</td> <td class="xl30" style="border-top: medium none; border-left: medium none; width: 69pt;" width="92">01-Jan-11</td> <td class="xl29" style="border-top: medium none; border-left: medium none; width: 48pt;" width="64">Title1</td> </tr> <tr style="height: 12.75pt;" height="17"> <td class="xl27" style="height: 12.75pt; border-top: medium none;" align="right" height="17">7</td> <td class="xl29" style="border-top: medium none; border-left: medium none; width: 48pt;" width="64">W</td> <td class="xl30" style="border-top: medium none; border-left: medium none; width: 69pt;" width="92">01-Jan-11</td> <td class="xl29" style="border-top: medium none; border-left: medium none; width: 48pt;" width="64">Title1</td> </tr> <tr style="height: 12.75pt;" height="17"> <td class="xl27" style="height: 12.75pt; border-top: medium none;" align="right" height="17">8</td> <td class="xl29" style="border-top: medium none; border-left: medium none; width: 48pt;" width="64">W</td> <td class="xl30" style="border-top: medium none; border-left: medium none; width: 69pt;" width="92">01-Jan-11</td> <td class="xl29" style="border-top: medium none; border-left: medium none; width: 48pt;" width="64">Title1</td> </tr> <tr style="height: 12.75pt;" height="17"> <td class="xl27" style="height: 12.75pt; border-top: medium none;" align="right" height="17">9</td> <td class="xl29" style="border-top: medium none; border-left: medium none; width: 48pt;" width="64">W</td> <td class="xl30" style="border-top: medium none; border-left: medium none; width: 69pt;" width="92">01-Jan-11</td> <td class="xl29" style="border-top: medium none; border-left: medium none; width: 48pt;" width="64">Title1</td> </tr> <tr style="height: 12.75pt;" height="17"> <td class="xl27" style="height: 12.75pt; border-top: medium none;" align="right" height="17">10</td> <td class="xl29" style="border-top: medium none; border-left: medium none; width: 48pt;" width="64">W</td> <td class="xl30" style="border-top: medium none; border-left: medium none; width: 69pt;" width="92">01-Jan-11</td> <td class="xl29" style="border-top: medium none; border-left: medium none; width: 48pt;" width="64">Title1</td> </tr> <tr style="height: 12.75pt;" height="17"> <td class="xl27" style="height: 12.75pt; border-top: medium none;" align="right" height="17">11</td> <td class="xl29" style="border-top: medium none; border-left: medium none; width: 48pt;" width="64">W</td> <td class="xl30" style="border-top: medium none; border-left: medium none; width: 69pt;" width="92">01-Jan-11</td> <td class="xl29" style="border-top: medium none; border-left: medium none; width: 48pt;" width="64">Title1</td> </tr> <tr style="height: 12.75pt;" height="17"> <td class="xl27" style="height: 12.75pt; border-top: medium none;" align="right" height="17">12</td> <td class="xl31" style="border-top: medium none; border-left: medium none; width: 48pt;" width="64">L</td> <td class="xl32" style="border-top: medium none; border-left: medium none; width: 69pt;" width="92">01-Feb-11</td> <td class="xl31" style="border-top: medium none; border-left: medium none; width: 48pt;" width="64">Title2</td> </tr> <tr style="height: 12.75pt;" height="17"> <td class="xl27" style="height: 12.75pt; border-top: medium none;" align="right" height="17">13</td> <td class="xl31" style="border-top: medium none; border-left: medium none; width: 48pt;" width="64">L</td> <td class="xl32" style="border-top: medium none; border-left: medium none; width: 69pt;" width="92">02-Feb-11</td> <td class="xl31" style="border-top: medium none; border-left: medium none; width: 48pt;" width="64">Title3</td> </tr> <tr style="height: 12.75pt;" height="17"> <td class="xl27" style="height: 12.75pt; border-top: medium none;" align="right" height="17">14</td> <td class="xl31" style="border-top: medium none; border-left: medium none; width: 48pt;" width="64">L</td> <td class="xl32" style="border-top: medium none; border-left: medium none; width: 69pt;" width="92">03-Feb-11</td> <td class="xl31" style="border-top: medium none; border-left: medium none; width: 48pt;" width="64">Title4</td> </tr> <tr style="height: 12.75pt;" height="17"> <td class="xl27" style="height: 12.75pt; border-top: medium none;" align="right" height="17">15</td> <td class="xl31" style="border-top: medium none; border-left: medium none; width: 48pt;" width="64">L</td> <td class="xl32" style="border-top: medium none; border-left: medium none; width: 69pt;" width="92">04-Feb-11</td> <td class="xl31" style="border-top: medium none; border-left: medium none; width: 48pt;" width="64">Title5</td> </tr> <tr style="height: 12.75pt;" height="17"> <td class="xl27" style="height: 12.75pt; border-top: medium none;" align="right" height="17">16</td> <td class="xl31" style="border-top: medium none; border-left: medium none; width: 48pt;" width="64">L</td> <td class="xl32" style="border-top: medium none; border-left: medium none; width: 69pt;" width="92">
</td> <td class="xl31" style="border-top: medium none; border-left: medium none; width: 48pt;" width="64">
</td> </tr> <tr style="height: 12.75pt;" height="17"> <td class="xl27" style="height: 12.75pt; border-top: medium none;" align="right" height="17">17</td> <td class="xl31" style="border-top: medium none; border-left: medium none; width: 48pt;" width="64">L</td> <td class="xl32" style="border-top: medium none; border-left: medium none; width: 69pt;" width="92">06-Feb-11</td> <td class="xl31" style="border-top: medium none; border-left: medium none; width: 48pt;" width="64">Title7</td> </tr> <tr style="height: 12.75pt;" height="17"> <td class="xl27" style="height: 12.75pt; border-top: medium none;" align="right" height="17">18</td> <td class="xl31" style="border-top: medium none; border-left: medium none; width: 48pt;" width="64">L</td> <td class="xl32" style="border-top: medium none; border-left: medium none; width: 69pt;" width="92">07-Feb-11</td> <td class="xl31" style="border-top: medium none; border-left: medium none; width: 48pt;" width="64">Title8</td> </tr> <tr style="height: 12.75pt;" height="17"> <td class="xl27" style="height: 12.75pt; border-top: medium none;" align="right" height="17">19</td> <td class="xl31" style="border-top: medium none; border-left: medium none; width: 48pt;" width="64">L</td> <td class="xl32" style="border-top: medium none; border-left: medium none; width: 69pt;" width="92">08-Feb-11</td> <td class="xl31" style="border-top: medium none; border-left: medium none; width: 48pt;" width="64">Title9</td> </tr> </tbody></table>
I'd like to use the headers in row 1 as the unique identifiers for each column. The macro will need to identify the last row of data across all columns in sheet 1, then insert the data from sheet 2 in the corresponding columns, beginning with row 2 in sheet 2. Will need to loop through several thousand rows. Must keep data being moved from sheet 2 to sheet 1 in the same row.

Any help would be most appreciated - thank you!!



<table border="0" cellpadding="0" cellspacing="0" width="284"><col style="width: 48pt;" width="64" span="2"> <col style="width: 69pt;" width="92"> <col style="width: 48pt;" width="64"> <tbody><tr style="height: 12.75pt;" height="17"> <td class="xl27" style="height: 12.75pt; width: 48pt;" align="right" width="64" height="17">
</td> <td class="xl28" style="border-left: medium none; width: 48pt;" width="64">
</td> <td class="xl28" style="border-left: medium none; width: 69pt;" width="92">
</td> <td class="xl28" style="border-left: medium none; width: 48pt;" width="64">
</td> </tr> <tr style="height: 12.75pt;" height="17"> <td class="xl27" style="height: 12.75pt; border-top: medium none;" align="right" height="17">
</td> <td class="xl29" style="border-top: medium none; border-left: medium none; width: 48pt;" width="64">
</td> <td class="xl30" style="border-top: medium none; border-left: medium none; width: 69pt;" width="92">
</td> <td class="xl29" style="border-top: medium none; border-left: medium none; width: 48pt;" width="64">
</td> </tr> <tr style="height: 12.75pt;" height="17"> <td class="xl27" style="height: 12.75pt; border-top: medium none;" align="right" height="17">
</td> <td class="xl29" style="border-top: medium none; border-left: medium none; width: 48pt;" width="64">
</td> <td class="xl30" style="border-top: medium none; border-left: medium none; width: 69pt;" width="92">
</td> <td class="xl29" style="border-top: medium none; border-left: medium none; width: 48pt;" width="64">
</td> </tr> <tr style="height: 12.75pt;" height="17"> <td class="xl27" style="height: 12.75pt; border-top: medium none;" align="right" height="17">
</td> <td class="xl29" style="border-top: medium none; border-left: medium none; width: 48pt;" width="64">
</td> <td class="xl30" style="border-top: medium none; border-left: medium none; width: 69pt;" width="92">
</td> <td class="xl29" style="border-top: medium none; border-left: medium none; width: 48pt;" width="64">
</td> </tr> <tr style="height: 12.75pt;" height="17"> <td class="xl27" style="height: 12.75pt; border-top: medium none;" align="right" height="17">
</td> <td class="xl29" style="border-top: medium none; border-left: medium none; width: 48pt;" width="64">
</td> <td class="xl30" style="border-top: medium none; border-left: medium none; width: 69pt;" width="92">
</td> <td class="xl29" style="border-top: medium none; border-left: medium none; width: 48pt;" width="64">
</td> </tr> <tr style="height: 12.75pt;" height="17"> <td class="xl27" style="height: 12.75pt; border-top: medium none;" align="right" height="17">
</td> <td class="xl29" style="border-top: medium none; border-left: medium none; width: 48pt;" width="64">
</td> <td class="xl30" style="border-top: medium none; border-left: medium none; width: 69pt;" width="92">
</td> <td class="xl29" style="border-top: medium none; border-left: medium none; width: 48pt;" width="64">
</td> </tr> <tr style="height: 12.75pt;" height="17"> <td class="xl27" style="height: 12.75pt; border-top: medium none;" align="right" height="17">
</td> <td class="xl29" style="border-top: medium none; border-left: medium none; width: 48pt;" width="64">
</td> <td class="xl30" style="border-top: medium none; border-left: medium none; width: 69pt;" width="92">
</td> <td class="xl29" style="border-top: medium none; border-left: medium none; width: 48pt;" width="64">
</td> </tr> <tr style="height: 12.75pt;" height="17"> <td class="xl27" style="height: 12.75pt; border-top: medium none;" align="right" height="17">
</td> <td class="xl29" style="border-top: medium none; border-left: medium none; width: 48pt;" width="64">
</td> <td class="xl30" style="border-top: medium none; border-left: medium none; width: 69pt;" width="92">
</td> <td class="xl29" style="border-top: medium none; border-left: medium none; width: 48pt;" width="64">
</td> </tr> <tr style="height: 12.75pt;" height="17"> <td class="xl27" style="height: 12.75pt; border-top: medium none;" align="right" height="17">
</td> <td class="xl29" style="border-top: medium none; border-left: medium none; width: 48pt;" width="64">
</td> <td class="xl30" style="border-top: medium none; border-left: medium none; width: 69pt;" width="92">
</td> <td class="xl29" style="border-top: medium none; border-left: medium none; width: 48pt;" width="64">
</td> </tr> <tr style="height: 12.75pt;" height="17"> <td class="xl27" style="height: 12.75pt; border-top: medium none;" align="right" height="17">
</td> <td class="xl29" style="border-top: medium none; border-left: medium none; width: 48pt;" width="64">
</td> <td class="xl30" style="border-top: medium none; border-left: medium none; width: 69pt;" width="92">
</td> <td class="xl29" style="border-top: medium none; border-left: medium none; width: 48pt;" width="64">
</td> </tr> <tr style="height: 12.75pt;" height="17"> <td class="xl27" style="height: 12.75pt; border-top: medium none;" align="right" height="17">
</td> <td class="xl29" style="border-top: medium none; border-left: medium none; width: 48pt;" width="64">
</td> <td class="xl30" style="border-top: medium none; border-left: medium none; width: 69pt;" width="92">
</td> <td class="xl29" style="border-top: medium none; border-left: medium none; width: 48pt;" width="64">
</td> </tr> <tr style="height: 12.75pt;" height="17"> <td class="xl27" style="height: 12.75pt; border-top: medium none;" align="right" height="17">
</td> <td class="xl31" style="border-top: medium none; border-left: medium none; width: 48pt;" width="64">
</td> <td class="xl32" style="border-top: medium none; border-left: medium none; width: 69pt;" width="92">
</td> <td class="xl31" style="border-top: medium none; border-left: medium none; width: 48pt;" width="64">
</td> </tr> <tr style="height: 12.75pt;" height="17"> <td class="xl27" style="height: 12.75pt; border-top: medium none;" align="right" height="17">
</td> <td class="xl31" style="border-top: medium none; border-left: medium none; width: 48pt;" width="64">
</td> <td class="xl32" style="border-top: medium none; border-left: medium none; width: 69pt;" width="92">
</td> <td class="xl31" style="border-top: medium none; border-left: medium none; width: 48pt;" width="64">
</td> </tr> <tr style="height: 12.75pt;" height="17"> <td class="xl27" style="height: 12.75pt; border-top: medium none;" align="right" height="17">
</td> <td class="xl31" style="border-top: medium none; border-left: medium none; width: 48pt;" width="64">
</td> <td class="xl32" style="border-top: medium none; border-left: medium none; width: 69pt;" width="92">
</td> <td class="xl31" style="border-top: medium none; border-left: medium none; width: 48pt;" width="64">
</td> </tr> <tr style="height: 12.75pt;" height="17"> <td class="xl27" style="height: 12.75pt; border-top: medium none;" align="right" height="17">
</td> <td class="xl31" style="border-top: medium none; border-left: medium none; width: 48pt;" width="64">
</td> <td class="xl32" style="border-top: medium none; border-left: medium none; width: 69pt;" width="92">
</td> <td class="xl31" style="border-top: medium none; border-left: medium none; width: 48pt;" width="64">
</td> </tr> <tr style="height: 12.75pt;" height="17"> <td class="xl27" style="height: 12.75pt; border-top: medium none;" align="right" height="17">
</td> <td class="xl31" style="border-top: medium none; border-left: medium none; width: 48pt;" width="64">
</td> <td class="xl32" style="border-top: medium none; border-left: medium none; width: 69pt;" width="92">
</td> <td class="xl31" style="border-top: medium none; border-left: medium none; width: 48pt;" width="64">
</td> </tr> <tr style="height: 12.75pt;" height="17"> <td class="xl27" style="height: 12.75pt; border-top: medium none;" align="right" height="17">
</td> <td class="xl31" style="border-top: medium none; border-left: medium none; width: 48pt;" width="64">
</td> <td class="xl32" style="border-top: medium none; border-left: medium none; width: 69pt;" width="92">
</td> <td class="xl31" style="border-top: medium none; border-left: medium none; width: 48pt;" width="64">
</td> </tr> <tr style="height: 12.75pt;" height="17"> <td class="xl27" style="height: 12.75pt; border-top: medium none;" align="right" height="17">
</td> <td class="xl31" style="border-top: medium none; border-left: medium none; width: 48pt;" width="64">
</td> <td class="xl32" style="border-top: medium none; border-left: medium none; width: 69pt;" width="92">
</td> <td class="xl31" style="border-top: medium none; border-left: medium none; width: 48pt;" width="64">
</td> </tr> <tr style="height: 12.75pt;" height="17"> <td class="xl27" style="height: 12.75pt; border-top: medium none;" align="right" height="17">
</td> <td class="xl31" style="border-top: medium none; border-left: medium none; width: 48pt;" width="64">
</td> <td class="xl32" style="border-top: medium none; border-left: medium none; width: 69pt;" width="92">
</td> <td class="xl31" style="border-top: medium none; border-left: medium none; width: 48pt;" width="64">
</td> </tr> </tbody></table>
 
Last edited:

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
Possibly use some sort of array to find the column headers in row 1, then move the specific rows into place? Just a little stumped on the VBA execution. Help is most appreciated!
 
Upvote 0
Code:
Sub Move_Data()

    Dim ws1 As Worksheet, ws2 As Worksheet
    Dim Lastrow1 As Long, Lastrow2 As Long
    Dim Found As Range, i As Long
    
    Set ws1 = Sheets("Sheet1") 'Destination sheet
    Set ws2 = Sheets("Sheet2") 'Source sheet
    
    Lastrow1 = ws1.Cells.Find("*", , , , xlByRows, xlPrevious).Row
    Lastrow2 = ws2.Cells.Find("*", , , , xlByRows, xlPrevious).Row
    
    Application.ScreenUpdating = False
    
    For i = 1 To ws2.Cells(1, Columns.Count).End(xlToLeft).Column
    
       If Not IsEmpty(ws2.Cells(1, i)) Then
    
           Set Found = ws1.Range("1:1").Find(ws2.Cells(1, i), , , , xlByColumns, xlNext, False)
           
           If Not Found Is Nothing Then
               ws1.Cells(Lastrow1 + 1, Found.Column).Resize(Lastrow2 - 1).Value = ws2.Range(ws2.Cells(2, i), ws2.Cells(Lastrow2, i)).Value
           End If
       End If
    Next i
    
    Application.ScreenUpdating = True
     
End Sub
 
Upvote 0
Thanks so much for your help AlphaFrog, much appreciated.

However, this didn't quite work - the macro only moved the 4th column (D) on sheet 2 into the second column in sheet 1. Maybe I should have been more detailed about this in my original post, but I'm trying to make this work off of the headers in row 1. For example, the Deal_Date column could be in column E, F, or G, so I'm trying to find a way to move the info from one sheet to another based on the column headers in row 1.

Sheet 1:
<TABLE style="WIDTH: 202pt; BORDER-COLLAPSE: collapse" border=0 cellSpacing=0 cellPadding=0 width=270><COLGROUP><COL style="WIDTH: 48pt" width=64><COL style="WIDTH: 53pt; mso-width-source: userset; mso-width-alt: 2596" span=2 width=71><COL style="WIDTH: 48pt" width=64><TBODY><TR style="HEIGHT: 15pt" height=20><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext 0.5pt solid; BACKGROUND-COLOR: transparent; WIDTH: 48pt; HEIGHT: 15pt; BORDER-TOP: windowtext 0.5pt solid; BORDER-RIGHT: windowtext 0.5pt solid" class=xl65 height=20 width=64>Library</TD><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext; BACKGROUND-COLOR: transparent; WIDTH: 53pt; BORDER-TOP: windowtext 0.5pt solid; BORDER-RIGHT: windowtext 0.5pt solid" class=xl65 width=71></TD><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext; BACKGROUND-COLOR: transparent; WIDTH: 53pt; BORDER-TOP: windowtext 0.5pt solid; BORDER-RIGHT: windowtext 0.5pt solid" class=xl65 width=71>Deal_Date</TD><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext; BACKGROUND-COLOR: transparent; WIDTH: 48pt; BORDER-TOP: windowtext 0.5pt solid; BORDER-RIGHT: windowtext 0.5pt solid" class=xl65 width=64>Title</TD></TR><TR style="HEIGHT: 15pt" height=20><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext 0.5pt solid; BACKGROUND-COLOR: transparent; HEIGHT: 15pt; BORDER-TOP: windowtext; BORDER-RIGHT: windowtext 0.5pt solid" class=xl65 height=20>Lib1</TD><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext; BACKGROUND-COLOR: transparent; BORDER-TOP: windowtext; BORDER-RIGHT: windowtext 0.5pt solid" class=xl66></TD><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext; BACKGROUND-COLOR: transparent; BORDER-TOP: windowtext; BORDER-RIGHT: windowtext 0.5pt solid" class=xl66 align=right>4/1/2010</TD><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext; BACKGROUND-COLOR: transparent; BORDER-TOP: windowtext; BORDER-RIGHT: windowtext 0.5pt solid" class=xl65>Title1</TD></TR><TR style="HEIGHT: 15pt" height=20><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext 0.5pt solid; BACKGROUND-COLOR: transparent; HEIGHT: 15pt; BORDER-TOP: windowtext; BORDER-RIGHT: windowtext 0.5pt solid" class=xl65 height=20>Lib2</TD><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext; BACKGROUND-COLOR: transparent; BORDER-TOP: windowtext; BORDER-RIGHT: windowtext 0.5pt solid" class=xl66></TD><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext; BACKGROUND-COLOR: transparent; BORDER-TOP: windowtext; BORDER-RIGHT: windowtext 0.5pt solid" class=xl66 align=right>4/1/2010</TD><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext; BACKGROUND-COLOR: transparent; BORDER-TOP: windowtext; BORDER-RIGHT: windowtext 0.5pt solid" class=xl65>Title2</TD></TR></TBODY></TABLE>
Sheet2:
<TABLE style="WIDTH: 149pt; BORDER-COLLAPSE: collapse" border=0 cellSpacing=0 cellPadding=0 width=199><COLGROUP><COL style="WIDTH: 48pt" width=64><COL style="WIDTH: 53pt; mso-width-source: userset; mso-width-alt: 2596" width=71><COL style="WIDTH: 48pt" width=64><TBODY><TR style="HEIGHT: 15pt" height=20><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext 0.5pt solid; BACKGROUND-COLOR: transparent; WIDTH: 48pt; HEIGHT: 15pt; BORDER-TOP: windowtext 0.5pt solid; BORDER-RIGHT: windowtext 0.5pt solid" class=xl65 height=20 width=64>Library</TD><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext; BACKGROUND-COLOR: transparent; WIDTH: 53pt; BORDER-TOP: windowtext 0.5pt solid; BORDER-RIGHT: windowtext 0.5pt solid" class=xl65 width=71>Deal_Date</TD><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext; BACKGROUND-COLOR: transparent; WIDTH: 48pt; BORDER-TOP: windowtext 0.5pt solid; BORDER-RIGHT: windowtext 0.5pt solid" class=xl65 width=64>Title</TD></TR><TR style="HEIGHT: 15pt" height=20><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext 0.5pt solid; BACKGROUND-COLOR: transparent; HEIGHT: 15pt; BORDER-TOP: windowtext; BORDER-RIGHT: windowtext 0.5pt solid" class=xl65 height=20>Lib3</TD><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext; BACKGROUND-COLOR: transparent; BORDER-TOP: windowtext; BORDER-RIGHT: windowtext 0.5pt solid" class=xl66 align=right>8/1/2010</TD><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext; BACKGROUND-COLOR: transparent; BORDER-TOP: windowtext; BORDER-RIGHT: windowtext 0.5pt solid" class=xl65>Title3</TD></TR><TR style="HEIGHT: 15pt" height=20><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext 0.5pt solid; BACKGROUND-COLOR: transparent; HEIGHT: 15pt; BORDER-TOP: windowtext; BORDER-RIGHT: windowtext 0.5pt solid" class=xl65 height=20>Lib4</TD><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext; BACKGROUND-COLOR: transparent; BORDER-TOP: windowtext; BORDER-RIGHT: windowtext 0.5pt solid" class=xl66 align=right>8/1/2010</TD><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext; BACKGROUND-COLOR: transparent; BORDER-TOP: windowtext; BORDER-RIGHT: windowtext 0.5pt solid" class=xl65>Title4</TD></TR></TBODY></TABLE>

Becomes:
<TABLE style="WIDTH: 202pt; BORDER-COLLAPSE: collapse" border=0 cellSpacing=0 cellPadding=0 width=270><COLGROUP><COL style="WIDTH: 48pt" width=64><COL style="WIDTH: 53pt; mso-width-source: userset; mso-width-alt: 2596" span=2 width=71><COL style="WIDTH: 48pt" width=64><TBODY><TR style="HEIGHT: 15pt" height=20><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext 0.5pt solid; BACKGROUND-COLOR: transparent; WIDTH: 48pt; HEIGHT: 15pt; BORDER-TOP: windowtext 0.5pt solid; BORDER-RIGHT: windowtext 0.5pt solid" class=xl65 height=20 width=64>Library</TD><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext; BACKGROUND-COLOR: transparent; WIDTH: 53pt; BORDER-TOP: windowtext 0.5pt solid; BORDER-RIGHT: windowtext 0.5pt solid" class=xl65 width=71></TD><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext; BACKGROUND-COLOR: transparent; WIDTH: 53pt; BORDER-TOP: windowtext 0.5pt solid; BORDER-RIGHT: windowtext 0.5pt solid" class=xl65 width=71>Deal_Date</TD><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext; BACKGROUND-COLOR: transparent; WIDTH: 48pt; BORDER-TOP: windowtext 0.5pt solid; BORDER-RIGHT: windowtext 0.5pt solid" class=xl65 width=64>Title</TD></TR><TR style="HEIGHT: 15pt" height=20><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext 0.5pt solid; BACKGROUND-COLOR: transparent; HEIGHT: 15pt; BORDER-TOP: windowtext; BORDER-RIGHT: windowtext 0.5pt solid" class=xl65 height=20>Lib1</TD><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext; BACKGROUND-COLOR: transparent; BORDER-TOP: windowtext; BORDER-RIGHT: windowtext 0.5pt solid" class=xl66></TD><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext; BACKGROUND-COLOR: transparent; BORDER-TOP: windowtext; BORDER-RIGHT: windowtext 0.5pt solid" class=xl66 align=right>4/1/2010</TD><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext; BACKGROUND-COLOR: transparent; BORDER-TOP: windowtext; BORDER-RIGHT: windowtext 0.5pt solid" class=xl65>Title1</TD></TR><TR style="HEIGHT: 15pt" height=20><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext 0.5pt solid; BACKGROUND-COLOR: transparent; HEIGHT: 15pt; BORDER-TOP: windowtext; BORDER-RIGHT: windowtext 0.5pt solid" class=xl65 height=20>Lib2</TD><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext; BACKGROUND-COLOR: transparent; BORDER-TOP: windowtext; BORDER-RIGHT: windowtext 0.5pt solid" class=xl66></TD><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext; BACKGROUND-COLOR: transparent; BORDER-TOP: windowtext; BORDER-RIGHT: windowtext 0.5pt solid" class=xl66 align=right>4/1/2010</TD><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext; BACKGROUND-COLOR: transparent; BORDER-TOP: windowtext; BORDER-RIGHT: windowtext 0.5pt solid" class=xl65>Title2</TD></TR><TR style="HEIGHT: 15pt" height=20><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext 0.5pt solid; BACKGROUND-COLOR: transparent; HEIGHT: 15pt; BORDER-TOP: windowtext; BORDER-RIGHT: windowtext 0.5pt solid" class=xl65 height=20>Lib3</TD><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext; BACKGROUND-COLOR: transparent; BORDER-TOP: windowtext; BORDER-RIGHT: windowtext 0.5pt solid" class=xl66></TD><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext; BACKGROUND-COLOR: transparent; BORDER-TOP: windowtext; BORDER-RIGHT: windowtext 0.5pt solid" class=xl66 align=right>8/1/2010</TD><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext; BACKGROUND-COLOR: transparent; BORDER-TOP: windowtext; BORDER-RIGHT: windowtext 0.5pt solid" class=xl65>Title3</TD></TR><TR style="HEIGHT: 15pt" height=20><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext 0.5pt solid; BACKGROUND-COLOR: transparent; HEIGHT: 15pt; BORDER-TOP: windowtext; BORDER-RIGHT: windowtext 0.5pt solid" class=xl65 height=20>Lib4</TD><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext; BACKGROUND-COLOR: transparent; BORDER-TOP: windowtext; BORDER-RIGHT: windowtext 0.5pt solid" class=xl66></TD><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext; BACKGROUND-COLOR: transparent; BORDER-TOP: windowtext; BORDER-RIGHT: windowtext 0.5pt solid" class=xl66 align=right>8/1/2010</TD><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext; BACKGROUND-COLOR: transparent; BORDER-TOP: windowtext; BORDER-RIGHT: windowtext 0.5pt solid" class=xl65>Title4</TD></TR></TBODY></TABLE>

Does this make sense? Thanks for the help!
 
Upvote 0
It makes sense. The macro should look for the each header from sheet2 row1 and find its match on sheet1 in row1 no matter which column it's in. It worked for me.

Make sure the headers are exactly the same on both sheets. Case shouldn't matter. Make sure there are no extra characters, miss-spellings, or trailing spaces.
 
Upvote 0
Thank you so much AlphaFrog - looks like I had some problem with the spacing with my headers but works fine now.

The only small adjustment I would need to make is that if there the column from sheet 2 isn't found in sheet 1, then that column of data does not get moved (I should have put this in my original post, sorry).

As it is now, the macro moves all data into the corresponding columns with matching headers, which is great, but if it cannot find a matching header, it moves the data to the end column. Would there be a way to simply not move this data if the macro cannot find a matching column in sheet 1?

Again, thank you so much for all your help.
 
Upvote 0
My original macro doesn't copy the a column of data from sheet 2 if it can't find a header match on sheet1. So I don't know what you mean by....
but if it cannot find a matching header, it moves the data to the end column.

It doesn't do that. It only copies the column if it finds a header match.
 
Upvote 0
Does the macro look for an exact match in the header? The reason I ask is that sometimes I have a column marked Title_1 that comes before Title.

The macro will take the data in sheet2 marked Title and put it in Title_1 instead of the column marked just Title.

I'm wondering if this could be solved if the macro only found an exact match in the header in column 1?
 
Upvote 0
This will make it look for an exact match...

Code:
Set Found = ws1.Range("1:1").Find(ws2.Cells(1, i), , , [COLOR="Red"]xlWhole[/COLOR], xlByColumns, xlNext, False)
 
Upvote 0

Forum statistics

Threads
1,224,595
Messages
6,179,798
Members
452,943
Latest member
Newbie4296

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