+ Reply to Thread
Results 1 to 4 of 4

Do While - Until help

Hybrid View

Perez199202 Do While - Until help 05-14-2018, 05:56 PM
Logit Re: Do While - Until help 05-14-2018, 10:50 PM
Winon Re: Do While - Until help 05-15-2018, 12:11 AM
Perez199202 Re: Do While - Until help... 04-23-2020, 01:20 PM
  1. #1
    Registered User
    Join Date
    04-20-2018
    Location
    Costa Rica
    MS-Off Ver
    2013
    Posts
    7

    Do While - Until help

    Hi,

    I wanted to know if there's a way to do a loop meanwhile I have some filters applied in the sheet. I want to repeat the same macro until the active cell is not blank. If the active cell is blank stop the loop. Otherwise repeat the macro only for active cells.

    Here you have what I tried, the first option doesn't have the capability to let the code understand that offset to next row has to be in the next visible cell only.

    The second code will do the loop only for visible cells but whenever a cell is blank the debug message is stopping the code with an error.


        ActiveCell.Offset(1, 0).Select
        Do Until IsEmpty(ActiveCell.Value)
        Call No_Clear_Experience
        Loop
    
    
        Do Until ActiveCell.Offset(1, 0).SpecialCells(xlCellTypeVisible).Select
        If Active.cell.Value = " " Then Exit Do
        Call Useful_Yes
        Loop
    Last edited by Perez199202; 05-14-2018 at 05:58 PM.

  2. #2
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,424

    Re: Do While - Until help

    .
    Option Explicit
    Sub RunLoopUntil()
    
        Do Until IsEmpty(ActiveCell.Value)
        ActiveCell.Offset(1, 0).Select
        Call No_Clear_Experience
        Loop
    
    End Sub
    
    
    Sub No_Clear_Experience()
    'If Selection.Count > 1 Then Exit Sub
      With Range("A1")
        .Value = .Value + 1
    End With
    End Sub
    Attached Files Attached Files

  3. #3
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Do While - Until help

    Hello Perez199202,

    You can speed up the Code provided by Logit, as below;

    Option Explicit
    Sub RunLoopUntil()
    
       Application.Calculation = xlCalculationManual
        
        ActiveSheet.Range("A1").Activate
        ActiveSheet.Range("A1").Value = 0
        ActiveSheet.Range("A1").Value = Range("A1").Value
      Application.ScreenUpdating = False
        Do Until IsEmpty(ActiveCell.Value)
        ActiveCell.Offset(1, 0).Select
        Call No_Clear_Experience
        Loop
        
     Application.Calculation = xlCalculationAutomatic
      Application.ScreenUpdating = True
      
    End Sub
    
    
    Sub No_Clear_Experience()
    'If Selection.Count > 1 Then Exit Sub
      With ActiveSheet.Range("A1")
        .Value = .Value + 1
    End With
    End Sub
    Regards.
    Last edited by Winon; 05-15-2018 at 02:47 AM.
    Please consider:

    Be polite. Thank those who have helped you. Then Click on the star icon in the lower left part of the contributor's post and add Reputation. Cleaning up when you're done. If you are satisfied with the help you have received, then Please do Mark your thread [SOLVED] .

  4. #4
    Registered User
    Join Date
    04-20-2018
    Location
    Costa Rica
    MS-Off Ver
    2013
    Posts
    7

    Re: Do While - Until help [SOLVED]

    Thanks for the support! This is done

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

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