+ Reply to Thread
Results 1 to 3 of 3

VBA Copy match destination formatting

  1. #1
    Registered User
    Join Date
    05-30-2017
    Location
    Norwich
    MS-Off Ver
    2016 Professional Plus
    Posts
    11

    VBA Copy match destination formatting

    Hi,

    Very new to VBA and simply trying to arrange so that when I double click a cell, it adds the contents of that cell to the first empty cell within column F. The issue I am having is that when it copies it removes the formatting of the destination cell which is a table, so I lose the table edges. Is there a way to stop this? I've tried googling but code I includes always seems to cause an error.

    Code is:

    Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    If Not Intersect(Target, Range("B2:B268")) Is Nothing Then
    Cancel = True
    Target.Copy Destination:=Sheets("Cards").Range("F" & Rows.Count).End(xlUp).Offset(1)
    End If
    End Sub
    Thank you

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: VBA Copy match destination formatting

    Hi,
    Untested in the absence of the workbook but perhaps

    Please Login or Register  to view this content.
    Incidentally, avoid using sheet tab names in code, they are too easily changed and when that occurs your macro will fail. Use instead the VBA Sheet CODE name.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Registered User
    Join Date
    05-30-2017
    Location
    Norwich
    MS-Off Ver
    2016 Professional Plus
    Posts
    11

    Re: VBA Copy match destination formatting

    Thanks Richard. That worked flawlessly.

    I'm up against my next issue, which appears slightly more complex, however may not be.

    I need the above script to run for several separate columns on 1 sheet. I.e. 1 code will paste to column f, one to column g and so on.

    I have thought of getting round this by adding a right click menu, you then select the relevant column from the menu and it pastes to that column.

    How do I add the code above that you assisted me with into the following right click menu, so that when I click the option 'ClickMe' it runs the specified code?

    Option Explicit

    Public Const myBar As String = "MyPopupBar"


    Sub CreatePopup()
    Dim cmb As CommandBar
    Dim ctr As CommandBarControl

    DeletePopup

    Set cmb = Application.CommandBars.Add(myBar, msoBarPopup)
    Set ctr = cmb.Controls.Add(msoControlButton)

    With ctr
    .Caption = "ClickMe"
    .OnAction = "ClickMe"

    End With

    cmb.ShowPopup

    Set ctr = Nothing
    Set cmb = Nothing

    End Sub


    Sub DeletePopup()

    On Error Resume Next
    Application.CommandBars(myBar).Delete

    End Sub
    Thanks again!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Default to Match Destination Formatting
    By wingdub in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-22-2017, 08:47 AM
  2. VBA for Match Destination Formatting
    By wingdub in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-22-2017, 01:13 AM
  3. Match destination formatting for a specific range only
    By 11help11 in forum Excel General
    Replies: 3
    Last Post: 03-21-2017, 08:47 AM
  4. How to set key for 'Match Destination Formatting'?
    By LesliePrabakar in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 07-18-2016, 03:58 AM
  5. [SOLVED] How to set key for 'Match Destination Formatting'?
    By LesliePrabakar in forum Excel General
    Replies: 7
    Last Post: 07-16-2016, 10:16 AM
  6. [SOLVED] Default to Match Destination Formatting
    By johnph in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-13-2012, 09:38 AM
  7. [SOLVED] Automatically match destination formatting?
    By Nuttysmallbar in forum Excel General
    Replies: 2
    Last Post: 06-09-2005, 01:05 PM

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