+ Reply to Thread
Results 1 to 10 of 10

VBA - If statement and small piece of code

  1. #1
    Registered User
    Join Date
    12-17-2012
    Location
    Ireland
    MS-Off Ver
    Excel 2010
    Posts
    7

    VBA - If statement and small piece of code

    Hi,

    I am trying to automate a piece of work that I do a couple of times a week but I am new to VB so could really do with some help!

    Basically this is what I need to do:
    1. Copy data (number) from Col B to Col A but only if there is data present in Col E
    2. With the new data in Col A, change the second digit to an "x"
    3. If there is no data in Col E nothing needs to be done.

    I assume I will need to firstly do an if statement which in turn will carry out a copy command. After that it would just require code to change the second digit?

  2. #2
    Forum Contributor
    Join Date
    09-27-2012
    Location
    London, England
    MS-Off Ver
    2003, 2010
    Posts
    344

    Re: VBA - If statement and small piece of code

    Hi - Welcome to the forum. It would be helpful if you could upload a sample workbook along with your desired output.

    For points 1 and 3 the below code should work:

    Please Login or Register  to view this content.
    Re Point 2, if you could upload a sample output it would help me / someone in factoring that accordingly...

    To upload a workbook, click on the "Go Advanced" button below and click Attachments.

    Hope this helps.
    If solved kindly remember to mark Thread as solved.
    Click the small star icon at the bottom left of my post if this was useful.

  3. #3
    Registered User
    Join Date
    12-17-2012
    Location
    Ireland
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: VBA - If statement and small piece of code

    Hi, thanks for the quick reply. I have attached a work book, basically the first page is the output that I would like, the second is the original that I receive. This is just a small sample of what I need, hope it helps.
    Attached Files Attached Files

  4. #4
    Registered User
    Join Date
    12-17-2012
    Location
    Ireland
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: VBA - If statement and small piece of code

    Just tried your code and it certainly does most of what I want to do. The only thing is that if there is no data in Col E I do not want it to copy from Col B to Col A. I also need to try to make the second digit in Col A an "x"

  5. #5
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: VBA - If statement and small piece of code

    Quote Originally Posted by conorcleary View Post
    Hi,

    I am trying to automate a piece of work that I do a couple of times a week but I am new to VB so could really do with some help!

    Basically this is what I need to do:
    1. Copy data (number) from Col B to Col A but only if there is data present in Col E
    2. With the new data in Col A, change the second digit to an "x"
    3. If there is no data in Col E nothing needs to be done.

    I assume I will need to firstly do an if statement which in turn will carry out a copy command. After that it would just require code to change the second digit?
    Maybe this modification to kbkumar's code can help with Point 2.

    Please Login or Register  to view this content.

  6. #6
    Forum Contributor
    Join Date
    09-27-2012
    Location
    London, England
    MS-Off Ver
    2003, 2010
    Posts
    344

    Re: VBA - If statement and small piece of code

    Seeing your sample data, it seems that column E has got some cells that look "Blank" but has got spaces in them. Use the below modified code to overcome that:

    Please Login or Register  to view this content.
    Will work on the 2nd point in a bit...

  7. #7
    Registered User
    Join Date
    12-17-2012
    Location
    Ireland
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: VBA - If statement and small piece of code

    Thanks John, that worked a treat. Now the only issue is that I need to put in the exception that if there is no text in Col E do not copy from Col B to Col A

  8. #8
    Forum Contributor
    Join Date
    09-27-2012
    Location
    London, England
    MS-Off Ver
    2003, 2010
    Posts
    344

    Re: VBA - If statement and small piece of code

    Thanks John

    Conorcleary,

    Your final code should be:

    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    12-17-2012
    Location
    Ireland
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: VBA - If statement and small piece of code

    Thanks so much guys, works perfectly! Youve just saved me 5 hours per week!

  10. #10
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: VBA - If statement and small piece of code

    conorcleary and kbkumar, you are both welcome. Glad I could help out. Seems conorcleary has a working solution glad to hear that.

+ 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