+ Reply to Thread
Results 1 to 10 of 10

Check if value is in range, and if so check cell on row empty

  1. #1
    Registered User
    Join Date
    06-12-2015
    Location
    England
    MS-Off Ver
    Microsoft 365
    Posts
    91

    Check if value is in range, and if so check cell on row empty

    Hiya,

    I have a cell with a number in, lets say C1, and another range of an undefined size from A2 downwards. I need to check if the range contains the number in C1. If it does then check if column E on that row is empty. If empty, paste selection, if not empty, message box yes/no, if yes then paste selection.

    Thanks in advance for any help.

    Tim

  2. #2
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,926

    Re: Check if value is in range, and if so check cell on row empty

    This could be done with a regular formula
    =if(index(E:E,match(C1,A:A,0)="","Yes/"No",index(E:E,match(C1,A:A,0))
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  3. #3
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Check if value is in range, and if so check cell on row empty

    May be
    Please Login or Register  to view this content.
    < ----- Please click the little star * next to add reputation if my post helps you
    Visit Forum : From Here

  4. #4
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,648

    Re: Check if value is in range, and if so check cell on row empty

    Please give this a try...

    Please Login or Register  to view this content.
    Regards
    sktneer


    Treat people the way you want to be treated. Talk to people the way you want to be talked to.
    Respect is earned NOT given.

  5. #5
    Registered User
    Join Date
    06-12-2015
    Location
    England
    MS-Off Ver
    Microsoft 365
    Posts
    91

    Re: Check if value is in range, and if so check cell on row empty

    Thanks for the reply but it needs to be part of a larger macro. Also, I don't think I made the last bit very clear.

    To put it another way.

    Check if range in A contains C1. If it doesn't, call another macro. If it does then check if E on that row is empty.
    If E is empty then paste selection in that cell. If it isn't empty then present a YesNo message box saying "Would you like to overwrite".
    If yes, then paste the selection in the cell. If no then end.

  6. #6
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,648

    Re: Check if value is in range, and if so check cell on row empty

    In the proposed solution, replace the line MsgBox "The number " & Range("C1").Value & " was not found in column A.", vbExclamation with Call YourMacro where YourMacro is the sub-routine you wish to call if the number is not found in column A.

  7. #7
    Registered User
    Join Date
    06-12-2015
    Location
    England
    MS-Off Ver
    Microsoft 365
    Posts
    91

    Re: Check if value is in range, and if so check cell on row empty

    Oops, other people posted the responses while I was writing mine.

    Thanks for the replies. I've tried and works perfectly so thanks a lot for the quick response.

  8. #8
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,648

    Re: Check if value is in range, and if so check cell on row empty

    You're welcome! Glad we could help.

  9. #9
    Registered User
    Join Date
    06-12-2015
    Location
    England
    MS-Off Ver
    Microsoft 365
    Posts
    91

    Re: Check if value is in range, and if so check cell on row empty

    Hiya,

    I've made a few changes to fit my sheet but I'm now getting an error. Not sure what I've done to it that's wrong.

    Please Login or Register  to view this content.
    I'm getting "Object variable or With block variable not set" on

    If Cells(rEmp.Row, "B") = vbNullString Then

    Any ideas?

    Tim

  10. #10
    Registered User
    Join Date
    06-12-2015
    Location
    England
    MS-Off Ver
    Microsoft 365
    Posts
    91

    Re: Check if value is in range, and if so check cell on row empty

    Ah no, I see it now. If not sDate should have been if not rEmp.

+ 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. Check for multiple range and if any cell is not empty do something
    By tohor in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 03-31-2017, 12:24 PM
  2. Check for empty cell in a range of #N/A cells
    By Ramo13541 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-08-2016, 05:27 AM
  3. Check range A10 to A45 and if cell not empty then same line in B must have value
    By CAVA30 in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 03-08-2013, 09:25 PM
  4. Check for each cell in range if is it empty when user click to some cells
    By cronet in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-01-2013, 04:35 PM
  5. Check if any cell ina range is empty then kill macro
    By dcgrove in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-18-2011, 03:17 PM
  6. Check for empty range
    By gtmeloney in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-06-2009, 02:09 PM
  7. check if any cell in a dynamic range is empty
    By akabraha in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-30-2008, 04:13 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