Results 1 to 18 of 18

VBA Sorting Nth Range not working

Threaded View

beechum1 VBA Sorting Nth Range not... 05-16-2009, 04:29 AM
Roger Govier Re: VBA Sorting Nth Range not... 05-16-2009, 05:55 AM
beechum1 Re: VBA Sorting Nth Range not... 05-16-2009, 03:10 PM
shg Re: VBA Sorting Nth Range not... 05-16-2009, 03:55 PM
beechum1 Re: VBA Sorting Nth Range not... 05-16-2009, 04:57 PM
beechum1 Re: VBA Sorting Nth Range not... 05-16-2009, 09:27 PM
beechum1 Re: VBA Sorting Nth Range not... 05-16-2009, 09:48 PM
  1. #1
    Registered User
    Join Date
    01-15-2006
    Posts
    46

    VBA Sorting Nth Range not working

    I have a values in column C of stuff1, stuff2 and on down.

    I have a value in cell A1.

    I want to start in C1, and every Nth, where N is the value in cell A1, select and paste into column H.

    My problem is that the selected cells don't start in C1, in fact, based on the value in A1, it starts in different cells in column C. AND, if i press the button twice, the returned values are different.

    Private Sub CommandButton1_Click()
    'Sub SelectEveryNthCell()
        Dim rRange As Range
        Dim rEveryNth As Range
        Dim lRow As Long
         
        With Sheet1
            Set rRange = .Range("C1", .Cells(.Rows.Count, "C").End(xlUp))
        End With
         
        For lRow = 1 To rRange.Rows.Count Step Range("a1").Value
        
            If lRow = 1 Then
                Set rEveryNth = rRange(lRow, 1)
            Else
                Set rEveryNth = Union(rRange(lRow, 1), rEveryNth)
            End If
        Next lRow
         
        Application.Goto rEveryNth
        
        Selection.Copy
        
        ActiveSheet.Range("j1").Select
        
        Selection.PasteSpecial Paste:=xlPasteValues, _
        Operation:=xlNone, _
        SkipBlanks:=False, _
        Transpose:=False
    
    
    End Sub
    Link to source code
    i've attached a sample.
    Attached Files Attached Files

Thread Information

Users Browsing this Thread

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

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