+ Reply to Thread
Results 1 to 2 of 2

how do I copy and paste cells with a macro?

Hybrid View

  1. #1
    Registered User
    Join Date
    01-11-2011
    Location
    cleveland ohio
    MS-Off Ver
    Excel 2007
    Posts
    16

    Exclamation how do I copy and paste cells with a macro?

    Someone on this forum was kind enough to help me with this code, I have follow up questions, but he is in New Zealand and it's saturday morning and I don't expect him to wake up and head straight to this forum. Project is almost due. I am stuck

    The macro works well. If you click on the checkbox, the cell contents are copied and pasted from column k to column m and back. I want to be able to click and copy and paste data from columns I, J, K and back, and even from columns that are not next to each other. I cant figure it out. I keep getting compiler errors. I attached a dummy file of my work. It is in Excel 2007

    Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
        ' this is column A to double click for simulated checkbox action
        Const ActionCol = 2
        
        With Target
            If .Column = ActionCol Then
                Cancel = True
                With Application
                    .EnableEvents = False
                    .ScreenUpdating = False
                End With
                With .Font
                        .Name = "Wingdings 2"
                        .Size = 13
                End With
                If .Value = "£" Then ' if unchecked do this
                    .Value = "T"
                    Cells(.Row, "K").Copy
                    Cells(.Row, "M").PasteSpecial xlPasteValues
                     Cells(.Row, "K").ClearContents
                Else ' if checked or blank do this
                    .Value = "£"
                    Cells(.Row, "M").Copy
                    Cells(.Row, "K").PasteSpecial xlPasteValues
                    Cells(.Row, "M").ClearContents
                End If
                With Application
                    .EnableEvents = True
                    .ScreenUpdating = True
                End With
            End If
        End With
    
    End Sub
    Thank you very much

    this is the important part.

    If .Value = "£" Then ' if unchecked do this
                    .Value = "T"
                    Cells(.Row, "K").Copy
                    Cells(.Row, "M").PasteSpecial xlPasteValues
                     Cells(.Row, "K").ClearContents
                Else ' if checked or blank do this
                    .Value = "£"
                    Cells(.Row, "M").Copy
                    Cells(.Row, "K").PasteSpecial xlPasteValues
                    Cells(.Row, "M").ClearContents
    Thank you for your help!
    Attached Files Attached Files
    Last edited by spamunch; 01-14-2011 at 03:26 PM.

  2. #2
    Registered User
    Join Date
    05-20-2014
    Posts
    1

    Re: how do I copy and paste cells with a macro?

    great script! is there a way to add a second column of checks, and when each is checked it will delete or hide the row, or move the row to another sheet?

+ 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