Advertisement

03.12.2008 at 09:45AM PDT, ID: 23235762
[x]
Attachment Details

Excel macro to shift columns data

Asked by dbfromnewjersey in Microsoft Office Suite, Microsoft Excel Spreadsheet Software, Microsoft Applications

I asked an almost identical question earlier today but I made a mistake in my question and I'm trying to figure out how to modify the code I was given by MatthewsPatrick, one of the experts on here.

I have an Excel spreadsheet with 8 columns.  It looks like this:

(Col A)      (Coumn B)       (Column C)   (Column D)    (Column E)     (ColumnF)    (ColumnG)   (ColumnH)
    Date      Store Number   First Name1  Last Name1  First Name2   Last Name2  FirstName3  LastName3
1/1/2007           1                   John              Smith             Steve            Johnson       Diane         Beck
1/1/2007           2                    Ed                 Wood                    
1/1/2007           3                    Bob               Marley           Bill                Clinton

The number of employees for a given Store Number could be anywhere from 1 to 3.  I need to shift all employees names into 1 column (creating additional rows as a result if there is more then 1 employee for a given store number).  So, using the example above, my expected results would be:

    Date         Store Number       Last Name             First Name      
1/1/2007              1                    John                      Smith            
1/1/2007              1                    Steve                    Johnson
1/1/2007              1                    Diane                     Beck
1/1/2007              2                    Ed                          Wood                    
1/1/2007              3                    Bob                        Marley              
1/1/2007              3                    Bill                          Clinton

In my original question, I had the first and last names appearing in 1 column. This is wrong. The first and last names are in seperate columns. So, the modification to the code I need is to look in the Last Name columns of each row (columns D, F, H).  If there is no value in column F or H, no row is to be added. If there is a value in column F, add a row and move the contents of columns E and F (first and last name) to the new row and keep the relationship with the State and Store Numbers the same. Do the same procedure for the first and last names in columns G and H.  I want to end up with a worksheet with 4 columns, namely Date, Store Number, First Name,  Last Name. In other words, all first names are appear in 1 column and all last names are to appear in 1 column. The only difference in my previous question is that the first and last names appear in seperate columns in my source file. I originally indicated that first and last name were combined in 1 column. This is wrong. Can anybody help me modify MatthewPatrick's code?  I'll post his code in a sec.

Start Free Trial
[+][-]03.12.2008 at 09:47AM PDT, ID: 21107967

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03.12.2008 at 09:50AM PDT, ID: 21107999

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Microsoft Office Suite, Microsoft Excel Spreadsheet Software, Microsoft Applications
Sign Up Now!
Solution Provided By: matthewspatrick
Participating Experts: 1
Solution Grade: A
 
 
[+][-]03.12.2008 at 09:52AM PDT, ID: 21108026

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03.12.2008 at 09:57AM PDT, ID: 21108089

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628