Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Creating a macro to swap cells but retain formatting

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


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Creating a macro to swap cells but retain formatting

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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 857
Default Creating a macro to swap cells but retain formatting

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



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Creating a macro to swap cells but retain formatting

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" wrote in message
...
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
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
How can I swap cells Josh W Excel Discussion (Misc queries) 6 March 10th 09 07:13 PM
swap values between two cells killdare Excel Worksheet Functions 3 November 26th 07 07:20 AM
retain cell formatting bob777 Excel Discussion (Misc queries) 1 November 2nd 05 05:02 PM
Swap contents of two cells Sterling Excel Discussion (Misc queries) 3 October 20th 05 06:04 PM
Swap Cells William Wolfe Excel Discussion (Misc queries) 4 June 16th 05 05:18 PM


All times are GMT +1. The time now is 03:56 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"