+ Reply to Thread
Results 1 to 18 of 18

Check entry in Excel column if data is in the same row of a different column with VBA

  1. #1
    Registered User
    Join Date
    06-20-2013
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    26

    Check entry in Excel column if data is in the same row of a different column with VBA

    Hi,

    I need to create a VBA code that will check to enure data is entered into column 'B' of a worksheet if data is populated into column 'I' for the same row.
    The data could be pasted in block at the same time and so there would be a need to cycle through a range.
    If any cell in column 'B' is blank but column 'I' has populated data, then a message box should be displayed and the whole update cancelled.

    Is this possible? Can anybody provide the VBA code for me to test?

  2. #2
    Registered User
    Join Date
    06-21-2013
    Location
    Wiltshire, UK
    MS-Off Ver
    365 Version 2210 Build 16.0.15726.20070
    Posts
    72

    Re: Check entry in Excel column if data is in the same row of a different column with VBA

    Code would be one way to do this, but if you are pasting a block of data why not use conditional formatting (CF)? You could set up a CF to highlight cells in B and I a particular colour (RED?) if I has data and B does not.

    Code wise, an entry by entry code would look something like this;
    Please Login or Register  to view this content.
    This could not be used after pasting however as it would generate an error - it only looks at a single row.

    A code to run after pasting would have to be manually run an look like;
    Please Login or Register  to view this content.
    Isskint, i get satisfaction out of helping others

  3. #3
    Registered User
    Join Date
    06-20-2013
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    26

    Re: Check entry in Excel column if data is in the same row of a different column with VBA

    Thanks but I can not use conditional formating because users tend to ignore it.
    Is there no way to automate this?

  4. #4
    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: Check entry in Excel column if data is in the same row of a different column with VBA

    Hello stanlelma,

    Copy and paste this macro into the worksheet where your data is/

    Right Click the Tab
    Select View Code...
    Paste the macro with CTRL+V

    Please Login or Register  to view this content.
    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!)

  5. #5
    Registered User
    Join Date
    06-20-2013
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    26

    Re: Check entry in Excel column if data is in the same row of a different column with VBA

    Thanks again,
    The code worked perfectly.

    However I have a new problem. I now have the two Sub Worksheet Change sets of code on the same worksheet.
    How do I combine these so that both work?

    Please Login or Register  to view this content.
    Last edited by Leith Ross; 07-08-2013 at 02:54 PM. Reason: Added Code Tags

  6. #6
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: Check entry in Excel column if data is in the same row of a different column with VBA

    It would probably be easiest to put them both in a module with unique names and under change your Worksheet_Change event to:

    Please Login or Register  to view this content.
    Please don't forget to use code tags around your code in posts.
    Thanks,
    Solus


    Please remember the following:

    1. Use [code] code tags [/code]. It keeps posts clean, easy-to-read, and maintains VBA formatting.
    Highlight the code in your post and press the # button in the toolbar.
    2. Show appreciation to those who have helped you by clicking below their posts.
    3. If you are happy with a solution to your problem, mark the thread as [SOLVED] using the tools at the top.

    "Slow is smooth, smooth is fast."

  7. #7
    Registered User
    Join Date
    06-20-2013
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    26

    Re: Check entry in Excel column if data is in the same row of a different column with VBA

    Sorry, How would I name the modules?

  8. #8
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: Check entry in Excel column if data is in the same row of a different column with VBA

    In the Visual Basic Editor (VBE) right click VBAProject in the project window and select add module. Double click the new module and paste this in the new module:

    Please Login or Register  to view this content.
    Then double click sheet one and your worksheet_change event will be:

    Please Login or Register  to view this content.

    Are you sure you need/want to run two separate loops every time you change your workbook?

  9. #9
    Registered User
    Join Date
    06-20-2013
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    26

    Re: Check entry in Excel column if data is in the same row of a different column with VBA

    Thanks, I followed your instructions but get Compile Error: Sub or Function not defined when I test.

  10. #10
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: Check entry in Excel column if data is in the same row of a different column with VBA

    Can you attach your workbook?

  11. #11
    Registered User
    Join Date
    06-20-2013
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    26

    Re: Check entry in Excel column if data is in the same row of a different column with VBA

    Thanks, Attached is that file. Entry in Cell A2 causes an error
    Attached Files Attached Files

  12. #12
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: Check entry in Excel column if data is in the same row of a different column with VBA

    stanlelma,

    My mistake. You need to remove Private from:
    Please Login or Register  to view this content.
    and
    Please Login or Register  to view this content.

  13. #13
    Registered User
    Join Date
    06-20-2013
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    26

    Re: Check entry in Excel column if data is in the same row of a different column with VBA

    Sorry, now I get Run-rime error: '424' Object Required.

  14. #14
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: Check entry in Excel column if data is in the same row of a different column with VBA

    Book1.xlsm


    Please refer to the code for sheet1 and module 1 in this example.

  15. #15
    Registered User
    Join Date
    06-20-2013
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    26

    Re: Check entry in Excel column if data is in the same row of a different column with VBA

    I have the same code. Still get error '424'

  16. #16
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: Check entry in Excel column if data is in the same row of a different column with VBA

    Where did you get this:
    Please Login or Register  to view this content.

  17. #17
    Registered User
    Join Date
    06-20-2013
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    26

    Re: Check entry in Excel column if data is in the same row of a different column with VBA

    It was a response to an early post. Works as a single Private Sub Worksheet_Change in a worksheet.
    However if the other code is added it will not.

  18. #18
    Registered User
    Join Date
    06-20-2013
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    26

    Re: Check entry in Excel column if data is in the same row of a different column with VBA

    Hi, Any progress with this?

+ 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