+ Reply to Thread
Results 1 to 6 of 6

Button linking to another cell and sheet

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    11-29-2003
    Posts
    1,203

    Another approach

    Here is code to do both. It does not randomize the data, it merely pull a random row each time ...

    Sub pullRandomRow()
    Dim ws1 As Worksheet
    Dim ws2 As Worksheet
    Dim lastRow As Long
    Dim nextRow As Long
    Dim rndRow As Long
    Dim rng As Range
    
        Randomize
        Set ws1 = Sheet1
        Set ws2 = Sheet2
        
        'last row on worksheet2
        lastRow = ws2.Cells(ws2.Rows.Count, 1).End(xlUp).Row
        'pick a random row
        rndRow = Int(((lastRow) * Rnd) + 1)  ' Generate random value between 1 and LastRow
        
        'move this row to next available row on worksheet1
        nextRow = ws1.Cells(ws1.Rows.Count, 1).End(xlUp).Row + 1
        If nextRow < 15 Then nextRow = 15
        
        Set rng = Range(ws2.Cells(rndRow, 1), ws2.Cells(rndRow, 4))
        rng.Copy Destination:=ws1.Range("A" & nextRow)
        ws1.Range("F" & nextRow) = rndRow
        
        'delete the row so we do not bring it over again
        ws2.Rows(rndRow).Delete
    
    End Sub

  2. #2
    Registered User
    Join Date
    01-06-2007
    Posts
    3
    Thank you very much for all your help and time with this. Everything is working great.

+ Reply to Thread

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