+ Reply to Thread
Results 1 to 7 of 7

Need to run a check before updating spreadsheet

Hybrid View

  1. #1
    Registered User
    Join Date
    07-10-2015
    Location
    Sacramento, California
    MS-Off Ver
    2010
    Posts
    17

    Need to run a check before updating spreadsheet

    I need to run a check where if column B = 0890-fed or 0890-DBW that column C must be between 10100 and 10199

    AND if column B = 0995, column C must between 17000 and 17999...if the conditions fail, a message will pop up with an error.

    Thank you!



    Tracking Log.JPG

  2. #2
    Valued Forum Contributor nigelbloomy's Avatar
    Join Date
    11-06-2013
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    1,011

    Re: Need to run a check before updating spreadsheet

    Does this do what you want?
    Sub test()
    Dim LastRow As Long
    LastRow = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row
    
    For i = 6 To LastRow
        If Cells(i, 2) = "0890-fed" Or Cells(i, 2) = "0890-DBW" Then
            If Not Cells(i, 3) <= 10199 And Cells(i, 3) >= 10100 Then
                GoTo errormsg
            End If
        End If
    
        If Cells(i, 2) = 995 Then
            If Not Cells(i, 3) <= 17999 And Cells(i, 3) >= 17000 Then
                GoTo errormsg
            End If
        End If
    Next i
    Exit Sub
    errormsg:
    MsgBox "You have problems", vbOKOnly
    
    End Sub
    Some people volunteer in soup kitchens or hospitals. I choose to make the world better by trying to help you with Excel. We're all learning.

    <---Click * Add Reputation for all helpful comments. It's like giving a smile.
    Forum Rules: How to mark your post [Solved] and have a happier, Excel enriched life.

  3. #3
    Registered User
    Join Date
    07-10-2015
    Location
    Sacramento, California
    MS-Off Ver
    2010
    Posts
    17

    Re: Need to run a check before updating spreadsheet

    Quote Originally Posted by nigelbloomy View Post
    Does this do what you want?
    Sub test()
    Dim LastRow As Long
    LastRow = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row
    
    For i = 6 To LastRow
        If Cells(i, 2) = "0890-fed" Or Cells(i, 2) = "0890-DBW" Then
            If Not Cells(i, 3) <= 10199 And Cells(i, 3) >= 10100 Then
                GoTo errormsg
            End If
        End If
    
        If Cells(i, 2) = 995 Then
            If Not Cells(i, 3) <= 17999 And Cells(i, 3) >= 17000 Then
                GoTo errormsg
            End If
        End If
    Next i
    Exit Sub
    errormsg:
    MsgBox "You have problems", vbOKOnly
    
    End Sub
    Is there a way to make sure includes the "various" cells? Those do not need to have the check run on them. Those cells are fine.

  4. #4
    Valued Forum Contributor nigelbloomy's Avatar
    Join Date
    11-06-2013
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    1,011

    Re: Need to run a check before updating spreadsheet

    Does this work for that?
    Sub test()
    Dim LastRow As Long
    LastRow = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row
    
    For i = 6 To LastRow
        If Cells(i, 2) = "0890-fed" Or Cells(i, 2) = "0890-DBW" Then
            If Not (Cells(i, 3) <= 10199 And Cells(i, 3) >= 10100) Or Cells(i, 3) = "Various" Then
                GoTo errormsg
            End If
        End If
    
        If Cells(i, 2) = 995 Then
            If Not (Cells(i, 3) <= 17999 And Cells(i, 3) >= 17000) Or Cells(i, 3) = "Various" Then
                GoTo errormsg
            End If
        End If
    Next i
    Exit Sub
    errormsg:
    MsgBox "You have problems", vbOKOnly
    
    End Sub

  5. #5
    Registered User
    Join Date
    07-10-2015
    Location
    Sacramento, California
    MS-Off Ver
    2010
    Posts
    17

    Re: Need to run a check before updating spreadsheet

    It's not skipping over the various cells, I'm trying to skip over those but I can't seem to get the code right.

  6. #6
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Need to run a check before updating spreadsheet

    Hi kevingcp

    If I understand the issue, use AutoFilter (filter out "various") then do the test on SpecialCells(xlcelltypevisible).
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  7. #7
    Valued Forum Contributor nigelbloomy's Avatar
    Join Date
    11-06-2013
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    1,011

    Re: Need to run a check before updating spreadsheet

    Sorry. It gets confusing when trying to use too many if and or statements in one line. I guess I got the format wrong. This way works and is more understandable.

    Sub test()
    Dim LastRow As Long
    LastRow = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row
    
    For i = 6 To LastRow
        If Cells(i, 3) <> "Various" Then
        If Cells(i, 2) = "0890-fed" Or Cells(i, 2) = "0890-DBW" Then
            If Not (Cells(i, 3) <= 10199 And Cells(i, 3) >= 10100) Then
                GoTo errormsg
            End If
        End If
    
        If Cells(i, 2) = 995 Then
            If Not (Cells(i, 3) <= 17999 And Cells(i, 3) >= 17000) Then
                GoTo errormsg
            End If
        End If
        End If
    Next i
    Exit Sub
    errormsg:
    MsgBox "You have problems", vbOKOnly
    
    End Sub

+ 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. updating a spreadsheet with new data from a separate spreadsheet
    By mikep374 in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 02-09-2014, 01:46 PM
  2. Macro to create check-box + updating reference cells
    By steam03 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-05-2013, 05:44 PM
  3. Data Comparison Check - Updating Cases
    By Nairobi Nice in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 11-08-2012, 05:32 PM
  4. Replies: 5
    Last Post: 05-09-2011, 04:53 PM
  5. Updating spreadsheet
    By bluestorm in forum Excel General
    Replies: 0
    Last Post: 06-09-2007, 04:21 PM
  6. help with updating spreadsheet
    By JAZZNAURA in forum Excel - New Users/Basics
    Replies: 2
    Last Post: 08-02-2006, 12:39 PM
  7. help with updating spreadsheet
    By JAZZNAURA in forum Excel General
    Replies: 0
    Last Post: 08-01-2006, 04:30 PM
  8. updating spreadsheet.
    By funkymonkUK in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-22-2005, 11:05 AM

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