+ Reply to Thread
Results 1 to 2 of 2

Swapping cell content to INCLUDE CELL FORMATTING (Text color, background color, etc)

  1. #1
    Registered User
    Join Date
    10-09-2014
    Location
    Salt Lake City
    MS-Off Ver
    2010
    Posts
    2

    Swapping cell content to INCLUDE CELL FORMATTING (Text color, background color, etc)

    Now how would one (swap cell content) to include CELL FORMATTING?

    This is the code I am trying to use. It works but it doesn't include cell formatting (text color, cell background, etc). It will only swap the text. Does not swap text color or cell background, etc.

    Sub Button1_Click()

    'Updateby20131120
    Dim Rng1 As Range, Rng2 As Range
    Dim arr1 As Variant, arr2 As Variant
    xTitleId = "KutoolsforExcel"
    Set Rng1 = Application.Selection
    Set Rng1 = Application.InputBox("Range1:", xTitleId, Rng1.Address, Type:=8)
    Set Rng2 = Application.InputBox("Range2:", xTitleId, Type:=8)
    Application.ScreenUpdating = False
    arr1 = Rng1.Value
    arr2 = Rng2.Value
    Rng1.Value = arr2
    Rng2.Value = arr1
    Application.ScreenUpdating = True
    End Sub

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,434

    Re: Swapping cell content to INCLUDE CELL FORMATTING (Text color, background color, etc)

    Well, you can't use an array method because you can't store the formatting.

    Guess you'd need to create a temporary (and hidden) worksheet. Then you can copy the whole first range there, move the second range across and then over-write the second range.

    Not sure how it would cope with formulae in the range(s) though.


    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


+ 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. Change a Range's cell background color to that of another cell's cond. format color
    By kamelkid2 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-31-2014, 12:57 PM
  2. Modify Cell Background Color based on cell content
    By CWDurkin in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 07-01-2014, 11:57 AM
  3. Change cell background color based on another cells background color
    By Queo in forum For Other Platforms(Mac, Google Docs, Mobile OS etc)
    Replies: 4
    Last Post: 06-10-2014, 05:28 AM
  4. Replies: 4
    Last Post: 12-29-2013, 11:41 PM
  5. Use VBA to lock all cell formatting except background color?
    By jmrazek in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-26-2009, 06:39 PM

Tags for this Thread

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