none
do until loop question (- quite silly!) RRS feed

  • Question

  • Dim c As Long Dim IERM As String c = 1 Do Until c > 89 IERM = Worksheets(ShtName).Cells(4, 3 + c).Value 'ShtName = sheet 29

    .

    . c = c + 1 Loop

    trying to figure out what is happening in the piece of code; my understanding is

    -value of cell(4,4) is stored in IERM

    -c incremented

    -value of cell (4,5) overwrites current value of IERM and this happens until c = 89

    That correct?

     
    Sunday, December 25, 2016 2:26 PM

Answers

  • Yes, that is correct.

    Check this with Debug.Print in the Direct window.

    Sub test()
    Dim ShtName As String
    Dim c As Long
    Dim IERM As String
    ShtName = "sheet 29"
    c = 1
    Do Until c > 89
    IERM = Worksheets(ShtName).Cells(4, 3 + c).Value 'ShtName = sheet 29
    
    Debug.Print IERM
    
    c = c + 1
    Loop
    End Sub
    

    Jan

    • Marked as answer by VBNovice01 Sunday, December 25, 2016 4:38 PM
    Sunday, December 25, 2016 3:26 PM

All replies

  • Yes, that is correct.

    Check this with Debug.Print in the Direct window.

    Sub test()
    Dim ShtName As String
    Dim c As Long
    Dim IERM As String
    ShtName = "sheet 29"
    c = 1
    Do Until c > 89
    IERM = Worksheets(ShtName).Cells(4, 3 + c).Value 'ShtName = sheet 29
    
    Debug.Print IERM
    
    c = c + 1
    Loop
    End Sub
    

    Jan

    • Marked as answer by VBNovice01 Sunday, December 25, 2016 4:38 PM
    Sunday, December 25, 2016 3:26 PM
  • so in my mind, there is no real point in keeping it there because it is not referenced anywhere else after
    Sunday, December 25, 2016 4:38 PM