Results 1 to 7 of 7

Thread: Subtraction Of Series Of Cells' / Array Values

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #3
    Forum Guru Rick Rothstein's Avatar
    Join Date
    Feb 2012
    Posts
    662
    Rep Power
    15
    Quote Originally Posted by PcMax View Post
    I'm using the following code
    Code:
    Option Explicit
    
    Sub CTest()
        Dim r   As Long
        Dim ka, k()
     Dim i   As Long
        
        r = Range("C" & Rows.Count).End(3).Row + 1
        
        ka = Range("C3:C" & r)
        
        ReDim k(1 To UBound(ka, 1), 1 To 1)
     
        For i = 1 To UBound(ka, 1) - 1
            k(i, 1) = ka(i + 1, 1) - ka(i, 1)
        Next
    
        Range("O3").Resize(UBound(k, 1)) = k
    End Sub
    I doubt if the time difference is measurable, but given what you are doing, you do not need the k array... just do your calculations back into the ka array itself...
    Code:
    Sub CTest()
        Dim r   As Long
        Dim ka
        Dim i   As Long
        
        r = Range("C" & Rows.Count).End(3).Row + 1
        
        ka = Range("C3:C" & r)
        
        For i = 1 To UBound(ka, 1) - 1
            ka(i, 1) = ka(i + 1, 1) - ka(i, 1)
        Next
        Range("O3").Resize(UBound(ka, 1)) = ka
    End Sub
    Last edited by Rick Rothstein; 10-26-2012 at 11:46 PM.

Similar Threads

  1. Replies: 4
    Last Post: 06-10-2013, 01:27 PM
  2. Replies: 1
    Last Post: 12-04-2012, 08:56 AM
  3. counting consecutive values in an array
    By 5ko in forum Excel Help
    Replies: 3
    Last Post: 12-04-2012, 03:49 AM
  4. Replies: 3
    Last Post: 08-05-2012, 09:16 PM
  5. Replies: 3
    Last Post: 04-08-2012, 09:44 AM

Posting Permissions

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