Thursday, 6 December 2012

Macro to paste values in next available cell or row

Hi All,
I was given a task which required me to copy, transpose and paste data from one worksheet to another. I completed this task in just 5 minutes with the following macro


Sub Macro1()
'
' Macro1 Macro
'

'
    Range("B1:B4").Select
    Selection.Copy
    Workbooks.Open Filename:="C:\Documents and Settings\ShruSoor\My Documents\Macro\Book2.xlsx"
    lMaxRows = Cells(Rows.Count, "A").End(xlUp).Row
Range("A" & lMaxRows + 1).Select
    Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
        SkipBlanks:=False, Transpose:=True
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=True
    ActiveWorkbook.Save
    ActiveWorkbook.Close
   
End Sub


Enjoy!!

No comments:

Post a Comment