copying formats

G

Guest

Hello again
I'm trying to simply copy only formats from one range to another and was just wondering if there was a way to do this similar to rng1.Values = rng2.Values

TIA
- Dustin Carter
 
F

Frank Kabel

Hi
try
Sub foo()
Dim rng1 As Range
Dim rng2 As Range
Set rng1 = Range("A1")
Set rng2 = Range("C1")
rng1.Copy Destination:=rng2
End Sub
 
T

Tom Ogilvy

I think Frank meant to say, not really.

Sub foo()
Dim rng1 As Range
Dim rng2 As Range
Set rng1 = Range("A1")
Set rng2 = Range("C1")
rng1.Copy
rng2.PasteSpecial Paste:=xlPasteFormats
End Sub

unless you want to equate the various attributes of interest

Sub foo()
Dim rng1 As Range
Dim rng2 As Range
Set rng1 = Range("A1")
Set rng2 = Range("C1")
rng2.font.name = rng1.font.name
rng2.font.bold = rng1.font.bold
rng2.font.colorindex = rng1.font.colorindex
' and so forth
End Sub
 
G

Guest

Hey Frank
Sorry for all the confusion, and thanks for the insanely fast reply, but I'm looking to copy only the formats. The code I have right now is

Sub foo(rng1, rng2
dim rng1 as range, rng2 as rang
rng1.Cop
rng2.PasteSpecial xlPasteFormat
Application.CutCopyMode = Fals
End Su

This method leaves rng2 selected and messes with any current clipboard values

Thanks again
- Dustin Carte

----- Frank Kabel wrote: ----

H
tr
Sub foo(
Dim rng1 As Rang
Dim rng2 As Rang
Set rng1 = Range("A1"
Set rng2 = Range("C1"
rng1.Copy Destination:=rng
End Su

--
Regard
Frank Kabe
Frankfurt, German


dcarter wrote
 
G

Guest

Well, thanks Tom. Your second suggestion really hadn't occured to me
rng2.font.name = rng1.font.name is exactly what I was looking for. The clipboard aspect of copying formats was driving me nuts

I really need to buy you a beer sometime

Thanks again
- Dustin Carte

----- Tom Ogilvy wrote: ----

I think Frank meant to say, not really

Sub foo(
Dim rng1 As Rang
Dim rng2 As Rang
Set rng1 = Range("A1"
Set rng2 = Range("C1"
rng1.Cop
rng2.PasteSpecial Paste:=xlPasteFormat
End Su

unless you want to equate the various attributes of interes

Sub foo(
Dim rng1 As Rang
Dim rng2 As Rang
Set rng1 = Range("A1"
Set rng2 = Range("C1"
rng2.font.name = rng1.font.nam
rng2.font.bold = rng1.font.bol
rng2.font.colorindex = rng1.font.colorinde
' and so fort
End Su
 
F

Frank Kabel

Hi
no problem, I understood your requet not correctly but Tom gave you
your solution :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top