+ Reply to Thread
Results 1 to 7 of 7

Macro to check Entire Column Q for 0 and stop macro

Hybrid View

  1. #1
    Registered User
    Join Date
    09-17-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    14

    Macro to check Entire Column Q for 0 and stop macro

    Hi

    Is it possible to have a macro to check the entire column Q for 0 (this is a number 0)

    and if it is present, it stops the macro?

  2. #2
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,551

    Re: Macro to check Entire Column Q for 0 and stop macro

    something like this

     Dim CellPtr As Long
     
     For CellPtr = 1 To Cells(Rows.Count, "Q").End(xlUp).Row
        If Cells(CellPtr, "Q").Value = 0 Then Exit For
     Next
    End Su
    Thanks,
    Mike

    If you are satisfied with the solution(s) provided, please mark your thread as Solved.
    Select Thread Tools-> Mark thread as Solved.

  3. #3
    Registered User
    Join Date
    09-17-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    14

    Re: Macro to check Entire Column Q for 0 and stop macro

    Thanks Mike

    Unfortunately it is not working.

    This is what my current macro do (bold is what i need in a macro):

    1. Open .CSV file
    2. Check Column Q for the value 0 (it will either have a two letter in a cell or a value 0)
    3. Stop Macro if there is a value 0

    4. If no value = 0, continue with the rest of the macro

  4. #4
    Registered User
    Join Date
    09-17-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    14

    Re: Macro to check Entire Column Q for 0 and stop macro

    Would this work?

    Columns("Q:Q").Select
    If Cells.Value = 0 Then GoTo SubErr

  5. #5
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,551

    Re: Macro to check Entire Column Q for 0 and stop macro

    Try this

     Dim CellPtr As Long
     
     For CellPtr = 1 To Cells(Rows.Count, "Q").End(xlUp).Row
        If Cells(CellPtr, "Q").Value = "0" Then Exit For
     Next
    End Sub

  6. #6
    Registered User
    Join Date
    09-17-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    14

    Re: Macro to check Entire Column Q for 0 and stop macro

    Still doesn't work.

    How about

    If column Q contain 0 go to end of macro?

  7. #7
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,551

    Re: Macro to check Entire Column Q for 0 and stop macro

    Whats doesnt work If there is a 0 in column Q the macro will stop?

    Stop at zero.xlsm


    If you want to stop the sub use Exit sub instead of Exit For
    Last edited by mike7952; 10-06-2012 at 12:40 PM.

+ 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