vbaexcelloopsdoevents

Interface Controls for DoEvent in Excel


I have a macro to loop through a range and return emails to .Display based on the

 DoEvents

element within my module. I iterate that:

row_number = 1
'And
Do
DoEvents
row_number = row_number +1 
'Then a bunch of formatting requirements
Loop Until row_number = 'some value

I am wondering if there would be an easy-ish way to incorporate a counter function within the interface where I fire this module to tell it where I want the starting row to be and where I want the ending row to be. For instance, if I had one cell that contains by "start on row" cell with an increase or decrease button to up the value or lower it, and then an "end on row" cell with two buttons that would increase or decrease the ending value based on which rows I needed to start or stop on? Does that make sense?

Thanks!


Solution

  • How about changing your 'do until' loop to a 'for next' loop? Something like?...

    Sub rowinput()
    
        Dim lngInputStartRow As Long
        Dim lngInputEndRow As Long
        Dim row_number As Long
    
        lngInputStartRow = Range("A1").Value 'specify your input cell here
        lngInputEndRow = Range("A2").Value
    
        For row_number = lngInputStartRow To lngInputEndRow
            DoEvents
        Next row_number
    
        'Then a bunch of formatting requirements
    
    End Sub