+ Reply to Thread
Results 1 to 7 of 7

macro script for IF & print functions

  1. #1
    Registered User
    Join Date
    09-29-2008
    Location
    Sydney
    MS-Off Ver
    2016
    Posts
    42

    macro script for IF & print functions

    hi everyone,

    I am trying to automate a print process.
    In the attached sample spreadsheet, I would like to have a macro to perform this function:

    IF sheet 1's cell a1 has a value or not, then sheet 2's cell a1 would equal sheet 1's cell a1, and print sheet 2.
    IF next row's column 1 has a value, then sheet 2's cell a1 would equal sheet 1's cell a1, and print sheet 2.
    This would continue until sheet 1's next row does not have any value present.

    Can anyone please help me out on this? Thank you so much!
    Attached Files Attached Files
    Last edited by rhua5436; 04-14-2011 at 11:04 AM.

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: macro help

    Your post does not comply with Rule 1 of our Forum RULES. Your post title should accurately and concisely describe your problem, not your anticipated solution. Use terms appropriate to a Google search. Poor thread titles, like Please Help, Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will be addressed according to the OP's experience in the forum: If you have less than 10 posts, expect (and respond to) a request to change your thread title. If you have 10 or more posts, expect your post to be locked, so you can start a new thread with an appropriate title.
    To change a Title on your post, click EDIT then Go Advanced and change your title, if 2 days have passed ask a moderator to do it for you.
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,459

    Re: macro script for IF & print functions

    It appears that you have followed Roy's instructions and updated the thread title.

    So, try:

    Please Login or Register  to view this content.

    Regards
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  4. #4
    Registered User
    Join Date
    09-29-2008
    Location
    Sydney
    MS-Off Ver
    2016
    Posts
    42

    Re: macro script for IF & print functions

    Hi TMShucks,

    Thanks for your help! But im sorry, i incorrectly wrote out my requirement.

    IF sheet 1's cell a1 has a value or not, then sheet 2's cell a1 would equal sheet 1's cell a1, and print sheet 2.
    IF next row's column 1 (a2) has a value, then sheet 2's cell a1 would equal that cell's value (sheet1's a2), and print sheet 2.This would continue until sheet 1's next row does not have any value present.

    Could you please help me modify the script you gave me? I tried.... but hopelessly failed.....

    Thank you so much!

  5. #5
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,459

    Re: macro script for IF & print functions

    That's how I interpreted your question and that's what the code does ... although I have assumed the range of cells in column 1 has no gaps in it

    Please Login or Register  to view this content.

    This:

    Please Login or Register  to view this content.

    works out the last row in column A with data in it. If that were, say, 6, it would be the same as:

    Please Login or Register  to view this content.

    And the loop would be:

    Please Login or Register  to view this content.

    This:

    Please Login or Register  to view this content.

    set the value of cell A1 in Sheet2 to the value in the "cell being processed".

    Please Login or Register  to view this content.

    prints it out, and:

    Please Login or Register  to view this content.

    loops around for the next value.


    So, what is it that doesn't work? Does it fail because it tries to print a sheet with no data in it? Are the sheets actually called Sheet1 and Sheet2? Which cells actually have data in them? How would you like me to help you modify the script?

  6. #6
    Registered User
    Join Date
    09-29-2008
    Location
    Sydney
    MS-Off Ver
    2016
    Posts
    42

    Re: macro script for IF & print functions

    yes! you are right! it works
    I ran the macro when i was in sheet 2 and it didn't work.
    but when i ran the macro when sheet 1 was open, it worked.

    Thank you so much for your help. Greatly appreciated!

  7. #7
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,459

    Re: macro script for IF & print functions

    You're welcome.

+ 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