+ Reply to Thread
Results 1 to 15 of 15

Custom formatting using either Macro or VB script

  1. #1
    Registered User
    Join Date
    11-18-2011
    Location
    AZ
    MS-Off Ver
    Excel 2003
    Posts
    8

    Custom formatting using either Macro or VB script

    Hi,

    Ok, what I am trying to do is this. I have a report at that I am trying to extract information from that can be copied and pasted into another which already has a VLOOKUP function implemented to reference data within a certain format.

    The report that has the source information is in a different format going down columns with multiple duplicate entries in various cells down the columns.

    I have a macro that seperates out the data from the report that I ened but I am having trouble getting the data to format the way I need automatically. I have tried using a Copy>Paste Special> Transpose but it causes the data to not format correctly. Transpose is the function that I believe I need because the format goes from left to right instead of down the page on the report that needs the ference data.

    I believe I could do this in VB by setting up a script that would say something a long the lines of this psuedo code:

    Index Column (select column)
    If Value, transpose to cell to right
    Else, leave blank

    Any ideas on how I could accomplish this?
    Last edited by xander208; 11-18-2011 at 02:14 PM.

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Macro or Function?

    Start by posting a sample workbook with a BEFORE/AFTER example in it.

    Click GO ADVANCED and use the paperclip icon to post up a copy of your workbook.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Registered User
    Join Date
    11-18-2011
    Location
    AZ
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: Custom formating using either Macro or VB script

    Hi Paul,

    The name of the thread of is now changed to reflect my issue. I have also attached a copy of an example.
    Attached Files Attached Files

  4. #4
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: Custom formating using either Macro or VB script

    hi, xander208, option, run code "test". The types are considered to be consecutive as in example file.
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    11-18-2011
    Location
    AZ
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: Custom formating using either Macro or VB script

    Looks like this is doing what I am needing, the only issue is on the script backend, im not understanding what all it is doing. Would you be able to possibly add a few comments to it?

    Also, would it be possible to modify the script so that i includes an additional column for a "product description" inbetween columns A & B (Product ID & Product Cost)?
    Last edited by xander208; 11-20-2011 at 03:04 PM.

  6. #6
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: Custom formating using either Macro or VB script

    can you post sample file containing exact data layout of your real-life file. I will add code to it together with comments

  7. #7
    Registered User
    Join Date
    11-18-2011
    Location
    AZ
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: Custom formating using either Macro or VB script

    Uploading a new copy. This is the exact format, though some of the naming conventions on the "types" are different. The rest is basically the same formats im working with.
    Attached Files Attached Files

  8. #8
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: Custom formating using either Macro or VB script

    please check attachment, run code "test", the code has been competely changed, comments added
    Attached Files Attached Files

  9. #9
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: Custom formating using either Macro or VB script

    please note, the file should be saved before running the code

  10. #10
    Registered User
    Join Date
    11-18-2011
    Location
    AZ
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: Custom formating using either Macro or VB script

    looks like that does what i need. only other question I have is is there any way to rename the macro from 'test' to something different?

  11. #11
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: Custom formating using either Macro or VB script

    yes, you can give it a different name (w/o spaces), goto Tools - Macros - select macro "test", press Change.
    The code name is in the following line at the top
    Please Login or Register  to view this content.

  12. #12
    Registered User
    Join Date
    11-18-2011
    Location
    AZ
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: Custom formating using either Macro or VB script

    ok. that worked. Thank you! One more thing i noticed, if i rename the file to anything other than the current name the macro will not run. Any suggestions?
    Last edited by xander208; 11-21-2011 at 12:03 PM.

  13. #13
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: Custom formating using either Macro or VB script

    I renamed the file and saved it, the code runs as expected as the file name is not hardcoded in it. There are 2 options that are checked before running the code to avoid errors:
    1)
    Please Login or Register  to view this content.
    makes sure the sheet the code would run has ""Product Description" in B1 cell
    2)
    Please Login or Register  to view this content.
    checks for word "Total" existing on th sheet.
    If you feel it's not required, you can comment them out by putting ' sign at the start of the row. But when you run the code on a sheet with different data layout (different header, table of data located say from Y2 cell) it would result in error.

  14. #14
    Registered User
    Join Date
    11-18-2011
    Location
    AZ
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: Custom formating using either Macro or VB script

    Ok, looks like everything is working. Was able to make another macro to work in conjunction with the script. I really appreciate the help!

  15. #15
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: Custom formatting using either Macro or VB script

    if you are satisfied with the help provided and there are no more outstanding issues, please mark the thread as Solved:

    Click the Edit button on your first post in the thread, Click Go Advanced, select [SOLVED] from the Prefix dropdown, then click Save Changes. If more than two days have elapsed, the Edit button will not appear -- ask a moderator to mark it.

+ 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