+ Reply to Thread
Results 1 to 2 of 2

Macro required based on column value

  1. #1
    Registered User
    Join Date
    12-15-2008
    Location
    India
    Posts
    1

    Macro required based on column value

    Hi All,

    We need your help in creating a macro to achieve the below output. We have an excel file(Rawdata.xls) which contains data as:
    C1 C2 C3 C4 C5 C6 C7
    12345 20 24/12/2007 07/03/2008 C 19/11/2008 19/11/2008
    124 10 4/12/2007 P 4/12/2007
    143 5 1/1/2006 07/03/200 A 07/03/2008

    C7 is the last update date.

    What we require is this data to be split into another excel file(Split.xls) based on the logic that:
    For C5 if the value is P there should be one insert, with the value of C1,C2,C3 and C5 .
    if the value is A there will be two inserts one for C5 = P, C1,C2,C3 and C5 . and the other for C7 = A. C1,C2,C3,C4 and C5 . and
    if the value is C there will be three inserts one for C7 = P ,the other for C7 = A. and finally C7=C .
    Basically if
    C5 =P consider C3...C4 and C6 will be null.
    C5 =A consider C3and C4 .C6 will be null.
    C5 =C consider all dates but C4 can be null.

    So the final output for the above three records would be:
    Case 1:
    C1 C2 C3 C4 C5 C6 C7
    12345 20 24/12/2007 Null P NULL 24/12/2007
    12345 20 24/12/2007 07/03/2008 A NULL 07/03/2008
    12345 20 24/12/2007 07/03/2008 C 19/11/2008 19/11/2008

    Case 2:
    C1 C2 C3 C4 C5 C6 C7
    124 10 4/12/2007 Null P Null 4/12/2007

    Case 3:
    C1 C2 C3 C4 C5 C6 C7
    143 5 1/1/2006 Null P Null 1/1/2006
    143 5 1/1/2006 07/03/2008 A Null 7/03/2008

    Thanks for any help.
    The sample scenario file has been uploaded.
    Attached Files Attached Files

  2. #2
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606
    I can't follow the logic.

    What do you mean by e.g. C7=P when C7 contains dates?

    Why in your first bit of output is C4 null in the first row but 7/3/2008 in the next two rows?

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1