Consulting

Results 1 to 6 of 6

Thread: Help with "Array fuctioons"

  1. #1
    VBAX Newbie
    Joined
    Dec 2013
    Posts
    1
    Location

    Help with "Array fuctioons"

    Start comment

    Hi, I've bee trying to do the following:

    Make it so that (pseudo code):
    Cells c columns 5:140 = cells a 5:140 / cells b 5:140

    But I haven't found a way to run a for loop through the cells to make this possible. I would put my attempts here but I haven't had much progress on it and including it wouldn't help.

    End comment

  2. #2
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,738
    Location
    I think this is what you're looking for.

    Option Explicit
    
    Sub LoopDemo()
        Dim rCell As Range
        
        For Each rCell In ActiveSheet.Range("A5:A140").Cells
            If rCell.Offset(0, 2).Value <> 0 Then rCell.Value = rCell.Offset(0, 1).Value / rCell.Offset(0, 2).Value
        Next
    End Sub
    Paul

  3. #3
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    The way I read it, it should be

    Sub LoopDemo()
    Dim rCell As Range
         
        For Each rCell In ActiveSheet.Range("A5:A140").Cells
        
            With rCell
            
                If .Offset(0, 1).Value <> 0 Then
                
                    .Offset(0, 2).Value = .Value / .Offset(0, 1).Value
                End If
            End With
        Next
    End Sub
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Another way without looping

    Sub NoLoopDemo()
         
        With ActiveSheet.Range("C5:C140")
        
            .Formula = "=IF(B5<>0,A5/B5,"""")"
            .Value = .Value
        End With
    End Sub
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  5. #5
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,738
    Location
    @XLD --

    The way I read it, it should be
    Agree

    You read it better

    Paul

    PS -- Welcome back -- we missed you

  6. #6
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by Paul_Hossler View Post
    PS -- Welcome back -- we missed you
    Thank-you. I missed VBAX and you guys
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

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