Results 1 to 4 of 4

Why is activecell moving more than down 1 in my for k loop?

Threaded View

  1. #1
    Registered User
    Join Date
    06-15-2017
    Location
    Saskatchewan, Canada
    MS-Off Ver
    Microsoft Office 2013
    Posts
    2

    Why is activecell moving more than down 1 in my for k loop?

    My for J loop works well, and the For k works ok for the first iteration then jumps to B19 and doesn't move. I want my program to work for the k loop to work identical to the J loop where it selects the next value before looping. Totalval is a sum containing the amount of rows in the data to create the number of iterations to calculate. Sorry about the message boxes in the code, It helps me to keep track of what everything is


    For k = 0 To totalvals Step 1
        
    For j = 0 To totalvals Step 1
            'MsgBox "in J for loop"
            If j = 0 Then
                'MsgBox "in for if J loop"
                Range("b3").Select
                'MsgBox ActiveCell.Value & " is the cell value"
            Else
            End If
        
            total = total + ActiveCell.Value
            ActiveCell.Offset(1, 0).Select
            'MsgBox " after offset, cell value is " & ActiveCell.Value
        
            If j = totalvals Then
                'MsgBox "j = total val now"
                profit = total * Range("h6")
                'MsgBox "Current total profit is " & profit
                total = 0
            Else
            End If
        Next j
        
       If k = 0 Then
            MsgBox " k = 0 , select cell c3 "
            MsgBox "profit from before " & profit & " " & "Starting total: " & total
            Range("c3").Select
            MsgBox "activecell.value is " & ActiveCell.Value
        Else
        End If
        
        total = total + ActiveCell.Value
        MsgBox " In K Current units sold " & total
        ActiveCell.Offset(1, 0).Select
        MsgBox " after offset, cell value is " & ActiveCell.Value
        MsgBox ActiveCell.Row & ActiveCell.Column
    
    next k
    Last edited by oveedrx; 06-15-2017 at 05:47 PM. Reason: Please use code tags!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Loop Autofill (based on activecell, not cell reference, varying row counts)
    By xtinct2 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-23-2015, 12:29 PM
  2. ActiveCell.FormulaR1C1 get next column in loop
    By dwr0211 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-13-2012, 09:29 PM
  3. Output contents of Activecell when Activecell may be string or numeric.
    By jfriddle in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-09-2012, 12:27 PM
  4. Moving from For...Next loop to subroutine and back to loop
    By zabrahamson in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-25-2011, 01:26 PM
  5. For each loop, 1004 error, if ... then "activecell.offset" attempt
    By AdamParker in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 07-22-2010, 03:30 PM
  6. Help: Activecell within Do loop problem
    By DavidShepherd in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-12-2005, 06:00 AM
  7. Loop with activecell.offset
    By mthomas in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-18-2005, 05:29 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1