mardi 15 mars 2016

VBA to copy specified random data from different workbook

Sub getdata()

'CTRL+J

    Windows("sample rnd.xlsm").Activate
    Range("A1:L5215").Select
    Range("A2").Activate
    Selection.Copy
    Application.CutCopyMode = False
    Selection.Copy
    Application.CutCopyMode = False
    Selection.Copy
    Windows("rnd sample draft.xlsm").Activate
    Sheets("Random Sample").Select
    Sheets("Random Sample").Name = "Random Sample"
    Range("A1").Select
    ActiveSheet.Paste
    Application.CutCopyMode = False
    ActiveWorkbook.Save
End Sub

Above is my code so far. It is just copying data from another another workbook and pasting it to my specified worksheet.

What I want is to get random data (rows) without duplicates and I always want to include the first row since it contains the header.

Also, I want to have a text box where I can input number so that I can specify how many data to get from the other workbook. Quite new to vba. need help.




Aucun commentaire:

Enregistrer un commentaire