Results 1 to 4 of 4
  1. #1
    Gold Lounger
    Join Date
    Jan 2004
    Location
    Italy
    Posts
    3,245
    Thanks
    0
    Thanked 0 Times in 0 Posts

    LOOP for 5 columns (2000)

    I have this code to loop in column AH.
    Now instead to repeat the same loop with different range is possible to use this code to loop all column from AH to AL

    Sub CICLA_COLONNE()

    Dim WS As Worksheet, RIGA As Long, DATA As String, SERV As String
    Set WS = Sheets("TABELLA_AND")

    RIGA = 2

    While Not WS.Range("AG" & RIGA) = Empty
    If WS.Range("AH" & RIGA) > Empty Then
    DATA = WS.Range("AG" & RIGA)
    SERV = WS.Range("AH1")
    TOTALE = WS.Range("AH" & RIGA)
    'Call SOMMA_CELLE_STAT(DATA, SERV)
    End If
    RIGA = RIGA + 1
    Wend

    End Sub

    in effect finish the first loop in AH goto the same loop for AI....AL

  2. #2
    WS Lounge VIP sdckapr's Avatar
    Join Date
    Jul 2002
    Location
    Pittsburgh, Pennsylvania, USA
    Posts
    11,225
    Thanks
    14
    Thanked 342 Times in 335 Posts

    Re: LOOP for 5 columns (2000)

    How about this?

    <pre>Option Explicit
    Sub CICLA_COLONNE()
    Dim WS As Worksheet, RIGA As Long
    Dim DATA As String, SERV As String
    Dim TOTALE As Integer, iCol As Integer

    Set WS = Sheets("TABELLA_AND")
    RIGA = 2
    With WS
    While Not .Range("AG" & RIGA) = Empty
    DATA = .Range("AG" & RIGA)
    For iCol = 34 To 38 'AH to AL
    If .Cells(RIGA, iCol) > Empty Then
    SERV = .Cells(1, iCol)
    TOTALE = .Cells(RIGA, iCol)
    'Call SOMMA_CELLE_STAT(DATA, SERV)
    End If
    Next
    RIGA = RIGA + 1
    Wend
    End With
    Set WS = Nothing
    End Sub</pre>


    Steve

  3. #3
    Gold Lounger
    Join Date
    Jan 2004
    Location
    Italy
    Posts
    3,245
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: LOOP for 5 columns (2000)

    work fine!
    Tks.

    But i cannot uderstand when i select and copy your code from here, when i paste in IDE vba the code is enlarged in one only line!!!???? how to resolve?

    I have paste in Wordpad and Notepad but the effect is the same???!!!

  4. #4
    WS Lounge VIP sdckapr's Avatar
    Join Date
    Jul 2002
    Location
    Pittsburgh, Pennsylvania, USA
    Posts
    11,225
    Thanks
    14
    Thanked 342 Times in 335 Posts

    Re: LOOP for 5 columns (2000)

    You can paste into a blank worksheet and then copy from there to VBA

    Steve

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •