Results 1 to 2 of 2

Macro Looping Based on First Cell of Range

Threaded View

Coeus Macro Looping Based on First... 07-17-2013, 02:53 AM
zbor Re: Macro Looping Based on... 07-17-2013, 03:10 AM
  1. #1
    Registered User
    Join Date
    01-22-2013
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    55

    Macro Looping Based on First Cell of Range

    Hi again all!

    Hope all is well in your Macro lands!

    I am trying to modify a code which I got feedback on but am still running through and trying to understand.

    I have highlighted the modified section as bold - basically extending it to a range I want to copy but still loop based on the first cell in this data - is this possible?

    The original thread is: http://www.excelforum.com/excel-prog...44#post3319444

    Can someone highlight what I'm doing wrong?



    Sub REFRESH_DATA()
    
    
    'Defines PAYNUM as the variable for payroll numbers.
    Dim PAYNUM As Variant, i As Long
    
    'Turns off screen updating.
    Application.ScreenUpdating = False
    
    
    For j = 1 To 12
    '****************************** STORE VARIABLES ******************************
    
    'Sources sheet to store variables from.
    With Sheets("Data - Month " & j)
    'Stores each value in column A as a variable.
    PAYNUM = .Range("A1", .Range("A:D" & Rows.Count).End(xlUp)).Value
    
    End With
    
    
    '****************************** COMPARE VARIABLES *****************************
    
    
    'Sources sheet to compare to.
    With Sheets("Summary")
    If IsArray(PAUNUM) = True Then
    'Loop through each PAYNUM variable.
    For i = 1 To UBound(PAYNUM)
    
    'Tests if the PAYNUM variable matches any value in column B.
    If IsError(Application.Match(PAYNUM(i, 1), .Columns(2), 0)) Then
    
    'If no match to PAYNUM variable is found adds value to the first empty cell in column B.
    .Range("B" & Rows.Count).End(xlUp).Offset(1).Value = PAYNUM(i, 1)
    
    End If
    
    Next i
    End If
    End With
    
    Next j
    '****************************** CLOSE *****************************


    'Turns on screen updating.
    Application.ScreenUpdating = True


    End Sub
    Last edited by Leith Ross; 07-17-2013 at 03:11 AM. Reason: Added Code Tags

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Named Range - looping through each cell
    By leshka_uk in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-12-2012, 06:16 AM
  2. For Loop not looping through whole range stopping after 1 cell
    By jeskit in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-19-2011, 08:43 AM
  3. Looping through a Cell Range
    By ryno88 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-11-2010, 05:16 PM
  4. Looping through specific worksheet and/or cell range
    By svenk in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-18-2009, 06:24 PM
  5. Determine if range has NO Blank Cells without looping through each cell in range
    By Excelenator in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-04-2006, 01:35 AM

Tags for this Thread

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