+ Reply to Thread
Results 1 to 4 of 4

Combining three command buttons into one

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    02-19-2013
    Location
    UK
    MS-Off Ver
    Excel 2019
    Posts
    677

    Combining three command buttons into one

    Hi,
    I have three command buttons and I want to redo the code to combine them into one.
    Is it possible?
    Help is appreciated.

    Commandbutton2

    Private Sub CommandButton2_Click()
    Sheets("CA Record").UnProtect "abcd"
    With Sheets("CA Record").Range("A1").CurrentRegion
        If .Rows.Count > 1 Then
            .Offset(1).Copy
            Sheets("CA Record").Range("J" & Rows.Count).End(xlUp).Offset(1).PasteSpecial xlPasteValuesAndNumberFormats
            .Offset(1).ClearContents
        End If
        Sheets("CA Record").Protect "abcd"
    End With
    
    End Sub
    commandButton 3
    Private Sub CommandButton3_Click()
    Sheets("WCMR").UnProtect "abcd"
    With Sheets("WCMR").Range("A1").CurrentRegion
        If .Rows.Count > 1 Then
            .Offset(1).Copy
            Sheets("WCMR").Range("N" & Rows.Count).End(xlUp).Offset(1).PasteSpecial xlPasteValuesAndNumberFormats
            .Offset(1).ClearContents
        End If
        Sheets("WCMR").Protect "abcd"
    End With
    
    End Sub
    Commandbutton 4
    Private Sub CommandButton4_Click()
    Sheets("DBR").UnProtect "abcd"
    With Sheets("DBR").Range("A1").CurrentRegion
        If .Rows.Count > 1 Then
            .Offset(1).Copy
            Sheets("DBR").Range("H" & Rows.Count).End(xlUp).Offset(1).PasteSpecial xlPasteValuesAndNumberFormats
            .Offset(1).ClearContents
        End If
        Sheets("DBR").Protect "abcd"
    End With
    
    End Sub
    Regards

  2. #2
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: Combining three command buttons into one

    Private Sub CommandButton2_Click()
    Sheets("CA Record").UnProtect "abcd"
    With Sheets("CA Record").Range("A1").CurrentRegion
        If .Rows.Count > 1 Then
            .Offset(1).Copy
            Sheets("CA Record").Range("J" & Rows.Count).End(xlUp).Offset(1).PasteSpecial xlPasteValuesAndNumberFormats
            .Offset(1).ClearContents
        End If
        Sheets("CA Record").Protect "abcd"
    End With
    
    Sheets("WCMR").UnProtect "abcd"
    With Sheets("WCMR").Range("A1").CurrentRegion
        If .Rows.Count > 1 Then
            .Offset(1).Copy
            Sheets("WCMR").Range("N" & Rows.Count).End(xlUp).Offset(1).PasteSpecial xlPasteValuesAndNumberFormats
            .Offset(1).ClearContents
        End If
        Sheets("WCMR").Protect "abcd"
    End With
    
    Sheets("DBR").UnProtect "abcd"
    With Sheets("DBR").Range("A1").CurrentRegion
        If .Rows.Count > 1 Then
            .Offset(1).Copy
            Sheets("DBR").Range("H" & Rows.Count).End(xlUp).Offset(1).PasteSpecial xlPasteValuesAndNumberFormats
            .Offset(1).ClearContents
        End If
        Sheets("DBR").Protect "abcd"
    End With
    
    End Sub
    If solved remember to mark Thread as solved

  3. #3
    Forum Contributor
    Join Date
    02-19-2013
    Location
    UK
    MS-Off Ver
    Excel 2019
    Posts
    677

    Re: Combining three command buttons into one

    Hi,
    I will certainly try this. I am now doing some ops work and will reply tomorrow.
    Thanks mate

  4. #4
    Forum Contributor
    Join Date
    02-19-2013
    Location
    UK
    MS-Off Ver
    Excel 2019
    Posts
    677

    Re: Combining three command buttons into one

    Hi Mate,
    It exactly does what it says on the tin.
    Well done and great help again. thanks .
    See you soon
    Regards

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1