+ Reply to Thread
Results 1 to 9 of 9

VBA If statement to copy certian text boxes depending on value

  1. #1
    Registered User
    Join Date
    12-12-2013
    Location
    Wisconsin
    MS-Off Ver
    Excel 2010
    Posts
    92

    VBA If statement to copy certian text boxes depending on value

    I have 5 text boxes that could collect data. Some of the text boxes may not have data in them and I wouldn't want them copied. I currently have:
    Please Login or Register  to view this content.
    So if txtName, txtUser and txtForm have text but txtCoName and txtPhone do not only those text boxes would be copied. Is there an if statement to only use the clipboard for the textboxes that contain text?

    Thanks for your help.

  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: VBA If statement to copy certian text boxes depending on value

    Something like this:
    Please Login or Register  to view this content.
    _________________
    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
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,525

    Re: VBA If statement to copy certian text boxes depending on value

    Untested but try this:

    Please Login or Register  to view this content.
    HTH

    Robert
    Last edited by Trebor76; 03-08-2017 at 02:04 AM. Reason: Delete superfluous code line
    ____________________________________________
    Please ensure you mark your thread as Solved once it is. Click here to see how
    If this post helps, please don't forget to say thanks by clicking the star icon in the bottom left-hand corner of my post

  4. #4
    Registered User
    Join Date
    12-12-2013
    Location
    Wisconsin
    MS-Off Ver
    Excel 2010
    Posts
    92

    Re: VBA If statement to copy certian text boxes depending on value

    Thank you JBeaucaire. This will only copy txtName, and no other fields. If txtName and txtFrom are filled out and the other three are not, I would like only those two to be copied to the clipboard.

  5. #5
    Registered User
    Join Date
    12-12-2013
    Location
    Wisconsin
    MS-Off Ver
    Excel 2010
    Posts
    92

    Re: VBA If statement to copy certian text boxes depending on value

    Trebor76 I tried your code and receive a Run-time error '-214702489 (80070057)': Could not find the specified object error. When I debug it highlights:
    Please Login or Register  to view this content.
    Thanks

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

    Re: VBA If statement to copy certian text boxes depending on value

    Quote Originally Posted by ciresuark View Post
    This will only copy txtName, and no other fields.
    What makes you think that? Read it through again. It tests each of your 4 fields and adds them to the clipboard if they are not blank.

  7. #7
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,525

    Re: VBA If statement to copy certian text boxes depending on value

    Trebor76 I tried your code and receive a Run-time error '-214702489 (80070057)': Could not find the specified object error. When I debug it highlights:
    Please attach a copy of your workbook devoid of sensitive information so we can actually see what's happening. Thanks.

  8. #8
    Registered User
    Join Date
    12-12-2013
    Location
    Wisconsin
    MS-Off Ver
    Excel 2010
    Posts
    92

    Re: VBA If statement to copy certian text boxes depending on value

    JBeaucaire your code did work. I changed the names of the text boxes after I posted this and didn't change them in the code you provided. My bad.

    Thanks for your help!!!

  9. #9
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,525

    Re: VBA If statement to copy certian text boxes depending on value

    I changed the names of the text boxes after I posted this and didn't change them in the code you provided
    I dare say that was probably the issue with my code too. Glad you got it sorted in the end.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] [SOLVED] Need Excel Code to copy one row to another sheet if row contains certian TEXT
    By Drscott21 in forum Excel Programming / VBA / Macros
    Replies: 18
    Last Post: 03-25-2016, 01:37 PM
  2. [SOLVED] need help to extract a certian chars in a text string
    By tuongtu3 in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 04-01-2014, 03:36 PM
  3. [SOLVED] Hide cell if certian cells equal a certian criteria
    By namluke in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 03-22-2014, 09:39 AM
  4. Copy and paste data if certian criteria is met
    By namluke in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-29-2014, 08:35 AM
  5. [SOLVED] Copy cells from each row into new sheet, depending on if statement
    By christopherL in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-28-2013, 08:06 AM
  6. Copy Excel text to Powerpoint text boxes
    By benihana269 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-15-2013, 12:30 AM
  7. [SOLVED] How to determine if a cell has certian text for first three characters
    By proepert in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 07-10-2012, 10:20 PM

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