PC Review


Reply
Thread Tools Rate Thread

Creating a macro to swap cells but retain formatting

 
 
JEFF
Guest
Posts: n/a
 
      16th Apr 2007
Greetings,

I have a macro that I am using to swap the contents of two cells. When I
use it I lose any character formatting that I have applied to the cell(s).
Does anyone have any insights into how to do a swap cell macro but retain
the formatting?

Sub SwitchCells()
'
' Macro created 4/13/2007 by willis

Range("k13") = Range("g13")
Range("g13") = Range("b13")
Range("b13") = Range("k13")
Range("k13") = ""
End Sub

Best regards!
Jeff


 
Reply With Quote
 
 
 
 
=?Utf-8?B?R2FyeScncyBTdHVkZW50?=
Guest
Posts: n/a
 
      16th Apr 2007
use Copy:

Sub jeff()
Dim rk As Range
Dim rg As Range
Dim rb As Range
Set rk = Range("K13")
Set rg = Range("G13")
Set rb = Range("B13")
rg.Copy rk
rb.Copy rg
rk.Copy rb
rk.Clear
End Sub

--
Gary''s Student - gsnu200715

 
Reply With Quote
 
=?Utf-8?B?VmVyZ2VsIEFkcmlhbm8=?=
Guest
Posts: n/a
 
      16th Apr 2007
Jeff,

maybe something like this

Sub SwitchCells()

Range("G13").Copy Range("K13")
Range("B13").Copy Range("G13")
Range("K13").Copy Range("B13")
Range("K13").ClearFormats
Range("K13").ClearContents

End Sub



--
Hope that helps.

Vergel Adriano


"JEFF" wrote:

> Greetings,
>
> I have a macro that I am using to swap the contents of two cells. When I
> use it I lose any character formatting that I have applied to the cell(s).
> Does anyone have any insights into how to do a swap cell macro but retain
> the formatting?
>
> Sub SwitchCells()
> '
> ' Macro created 4/13/2007 by willis
>
> Range("k13") = Range("g13")
> Range("g13") = Range("b13")
> Range("b13") = Range("k13")
> Range("k13") = ""
> End Sub
>
> Best regards!
> Jeff
>
>
>

 
Reply With Quote
 
JEFF
Guest
Posts: n/a
 
      16th Apr 2007
Thank you very much!

I have merged cells that I am working with. In this case I assume I have to
unmerge first before I swap. Does anyone have any advice?

<snip>
Range("B13").MergeCells = False
</snip>

Thanks!

"Vergel Adriano" <(E-Mail Removed)> wrote in message
news:085350D0-8D7D-4F91-B20F-(E-Mail Removed)...
> Jeff,
>
> maybe something like this
>
> Sub SwitchCells()
>
> Range("G13").Copy Range("K13")
> Range("B13").Copy Range("G13")
> Range("K13").Copy Range("B13")
> Range("K13").ClearFormats
> Range("K13").ClearContents
>
> End Sub
>
>
>
> --
> Hope that helps.
>
> Vergel Adriano
>
>
> "JEFF" wrote:
>
>> Greetings,
>>
>> I have a macro that I am using to swap the contents of two cells. When I
>> use it I lose any character formatting that I have applied to the
>> cell(s).
>> Does anyone have any insights into how to do a swap cell macro but retain
>> the formatting?
>>
>> Sub SwitchCells()
>> '
>> ' Macro created 4/13/2007 by willis
>>
>> Range("k13") = Range("g13")
>> Range("g13") = Range("b13")
>> Range("b13") = Range("k13")
>> Range("k13") = ""
>> End Sub
>>
>> Best regards!
>> Jeff
>>
>>
>>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro to swap cells Brian Cryer Microsoft Excel Discussion 3 14th Jul 2007 04:05 PM
Creating Macro Buttons and formatting Big H Microsoft Excel Misc 0 1st Nov 2006 10:08 PM
Creating a custom formatting Macro lance.schaeffer@gmail.com Microsoft Excel Programming 5 5th Sep 2006 10:31 PM
Creating links to cells with no content, but that have formatting =?Utf-8?B?Y2VyYWg=?= Microsoft Excel Misc 1 24th Jan 2006 11:31 PM
Cells do not Retain Formatting After Pasting. Robert Watson Microsoft Excel Discussion 4 8th Dec 2003 12:04 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:16 AM.