Consulting

Results 1 to 5 of 5

Thread: macro to copy and paste worksheet

  1. #1
    VBAX Tutor
    Joined
    Aug 2007
    Posts
    294
    Location

    macro to copy and paste worksheet

    Hi Experts

    Need to amend the current VBA code so that it can be changed - in a way that the user can paste worksheet "Sheet1" into any other worksheet(s) in the workbook other then worksheet "Task_Table1"

    Also need to the macro to function even if worksheet "Sheet1" is hidden.

    Sub Copy_Paste()
    Application.ScreenUpdating = False
    Sheets("Sheet1").Select
    ActiveWindow.SmallScroll Down:=-9
    Cells.Select
    Selection.Copy
    Sheets("Latam Santander").Select
    ActiveWindow.SmallScroll Down:=-18
    Cells.Select
    Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
    False, Transpose:=False
    Range("D13").Select

    Application.ScreenUpdating = True
    End Sub

  2. #2
    VBAX Mentor MaximS's Avatar
    Joined
    Sep 2008
    Location
    Stoke-On-Trent
    Posts
    360
    Location
    Can you please explain what exactly you want to copy (exact range) and where to paste?

    How do you want to chose destination workbook/worksheet?

  3. #3
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    Insert this into a Module and change the Sub Copy1 as needed.

    I submitted my speedup routine as a kb article months back but no response yet. They just make it easy to set/unset these things with just two calls.

    [VBA]Public glb_origCalculationMode As Integer

    Sub SpeedOn(Optional StatusBarMsg As String = "Running macro...")
    glb_origCalculationMode = Application.Calculation
    With Application
    .Calculation = xlCalculationManual
    .ScreenUpdating = False
    .EnableEvents = False
    .DisplayAlerts = False
    .Cursor = xlWait
    .StatusBar = StatusBarMsg
    .EnableCancelKey = xlErrorHandler
    End With
    End Sub

    Sub SpeedOff()
    With Application
    .Calculation = glb_origCalculationMode
    .ScreenUpdating = True
    .EnableEvents = True
    .DisplayAlerts = True
    .CalculateBeforeSave = True
    .Cursor = xlDefault
    .StatusBar = False
    .EnableCancelKey = xlInterrupt
    End With
    End Sub

    Sub Copy1()
    CopyFromTo "Sheet1", "Sheet2"
    End Sub

    Sub CopyFromTo(fromSheet As String, toSheet As String)
    SpeedOn
    Worksheets(fromSheet).Cells.Copy
    Worksheets(toSheet).Range("A1").PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
    False, Transpose:=False
    Application.CutCopyMode = False
    'Range("D13").Select
    SpeedOff
    End Sub[/VBA]

  4. #4
    VBAX Tutor
    Joined
    Aug 2007
    Posts
    294
    Location
    Thanks KH.

    Let me test and report back..

  5. #5
    VBAX Tutor david000's Avatar
    Joined
    Mar 2007
    Location
    Chicago
    Posts
    276
    Location
    [vba]
    Sub CopySheet1()
    Dim i As Long
    With Sheet1.UsedRange
    Sheet2.Range("A1").Resize(.Rows.Count, .Columns.Count).Value = .Value
    End With
    End Sub
    [/vba]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •