Quantcast
Channel: Excel IT Pro Discussions forum
Viewing all articles
Browse latest Browse all 11829

Copy and Paste Values Only - Worksheet Specific

$
0
0

Hello All,

I'm using the below code in order to paste values only in an Excel 2010 workbook.  Is there a way to adjust the macro so it only affects a specific worksheet within the workbook?  The worksheet's name is Attendance. 

Many thanks!

' ########################
' Event for Workbook Open.
' ########################
Private Sub Workbook_Open()
    blnSwitch = False
    
    ' Record the active cell.
    Set rngPrevious = ActiveCell
End Sub

' ######################
' Event for SheetChange.
' ######################
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
    ToggleEvents False
    If Application.CutCopyMode = xlCopy Or Application.CutCopyMode = xlCut Then
        Application.Undo
        Target.Value = rngPrevious.Value
    End If
    ToggleEvents True
End Sub

' ###############################
' Event for SheetSelectionChange.
' ###############################
Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
    If Not blnSwitch Then
        Set rngNext = Target
        blnSwitch = True
    Else
        Set rngPrevious = rngNext
        Set rngNext = Target
    End If
End Sub

' ####################################
' Toggle the application-level events.
' ####################################
Private Sub ToggleEvents(ByVal Status As Boolean)
    Application.EnableEvents = Status
End Sub


Viewing all articles
Browse latest Browse all 11829

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>