+ Reply to Thread
Results 1 to 12 of 12

Conditional Insert text in field

  1. #1
    Registered User
    Join Date
    09-17-2009
    Location
    NC, USA
    MS-Off Ver
    Excel 2003
    Posts
    6

    Conditional Insert text in field

    I am working on a macro which will search one field for a value, if that field is has a certain value, it will go to another field, if that field is also blank it will insert some info there.

    I am not sure how to complete this at all.

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Conditional Insert text in field

    Hello resnostyle,

    Welcome to the Forum!

    Your post doesn't provide much information. It would help to see how the data is laid out. When you say field (database term), are you referring to a cell on a Worksheet or something else? Do you want a VBA macro to this?
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

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

    Re: Conditional Insert text in field

    Hi Resnote, welcome to the forum.

    Posting your code and your pertinent worksheet with some before/after examples should make this easy for us to help.

    Click GO ADVANCED and use the paperclip icon to post up 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!)

  4. #4
    Registered User
    Join Date
    09-17-2009
    Location
    NC, USA
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: Conditional Insert text in field

    Thanks Leith Ross for the welcome.

    Sorry, I am a programmer and usually work with PHP and MySql, so my mind works in terms of databases.

    I am referring to a field on the a worksheet. Let me try to provide a few more details then. I have a very wide and long excel document.

    The fields I am working with are: DU, it holds United States for example. Because of the way our system is fields in CP, will not have United States. My plan is to create a excel marco which will copy the DU United States to the CP. However, I want to be sure nothing is in the CP field. I dont want it to overwrite information.

    Quote Originally Posted by Leith Ross View Post
    Hello resnostyle,

    Welcome to the Forum!

    Your post doesn't provide much information. It would help to see how the data is laid out. When you say field (database term), are you referring to a cell on a Worksheet or something else? Do you want a VBA macro to this?

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

    Re: Conditional Insert text in field

    Which columns are in question? Which column holds the values you call "DU" and which column holds the values you want tested and inserted if needed?

  6. #6
    Registered User
    Join Date
    09-17-2009
    Location
    NC, USA
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: Conditional Insert text in field

    I uploaded a sample that should help.
    Last edited by resnostyle; 09-17-2009 at 03:14 PM. Reason: Removed file.

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

    Re: Conditional Insert text in field

    This macro will insert the values from column DU into CP if CP is empty, regardless of what the value is. You can adjust the formula used in the highlighted code to add more criteria, if needed.

    Please Login or Register  to view this content.
    Change to this to only insert if "United States" is in the DU column:
    Please Login or Register  to view this content.
    Last edited by JBeaucaire; 09-17-2009 at 03:15 PM.

  8. #8
    Registered User
    Join Date
    09-17-2009
    Location
    NC, USA
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: Conditional Insert text in field

    Wow, you guys are fast here! Thanks.

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

    Re: Conditional Insert text in field

    Hopefully you saw the edit above with the alternate formula you can use for more specific criteria.

    If that takes care of your need, be sure to EDIT your original post, click Go Advanced and mark the PREFIX box [SOLVED].


    (Also, use the blue "scales" icon in our posts to leave Reputation Feedback, it is appreciated)

  10. #10
    Registered User
    Join Date
    09-17-2009
    Location
    NC, USA
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: Conditional Insert text in field

    I made the changes above and now its not working right.

    I get run-time error 1004.
    Application defined or object defined error.

    After clicking debug, it highlights this line:
    Please Login or Register  to view this content.

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

    Re: Conditional Insert text in field

    Let's see all the code, or at least all the code around the line you noted.

  12. #12
    Registered User
    Join Date
    09-17-2009
    Location
    NC, USA
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: Conditional Insert text in field

    Here it is:

    Please Login or Register  to view this content.

+ 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