Swapping Range Values

     

    (1) Swapping one columns values with another column values:Fixed\Pre-defined Range

     

     

    Copy the code

     

    Private Sub CommandButton1_Click()
    'variant indicates any data type
    Dim s As Variant
    'Assigning values to Variable
    s = Range("A1:A11")
    'Swapping A column values with B column
    Range("A1:A11").Value = Range("B1:B11").Value
    'Swaping B column values with A column,which is stored in variable
    Range("B1:B11").Value = s
    'End of sub procedure
    End Sub

     

     

    (2) Copy data from particular cell to till the end by creating New Workbook:

    Copy the Code:

    Private Sub CommandButton1_Click()
    (1)Create a new Workbook to paste required data
    Dim wkb As Workbook
    Set wkb = Workbooks.Add
    (2)Activate current workbook which consists of data
    ThisWorkbook.Activate
    (3)Define a variable "d" to store required data
    Dim d As Long
    (4)assigning value to variable, from range("A11") to till the end(last data cell)
    d = Range(Range("A11"), Range("A11").End(xlDown)).Rows.Count
    (5)Define values using cells property
    Range(Cells(11, 1), Cells((11 + d) - 1, 1)).Select
    On Error Resume Next
    Selection.Copy
    (6)Assigning destination for selected range Wkb=newly created workbook
    Selection.Copy Destination:=wkb.Sheets("Sheet1").Range("A1")
    (7)Paste the data
    wkb.Sheets("sheet1").Range("A1").PasteSpecial
    Application.CutCopyMode = False
    End Sub