Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default How can I copy range's style to another in Excel?

Hi everybody,

I have a problum that I selected a range on Excel worksheet, and inserted
another range on the same worksheet, now I wanna copy the selected range's
style to the inserted one, I use

insertedRange.Style = selectedRange.Style;

or

insertedRange.Cells.Style = selectedRange.Cells.Style;

both of the two works not correctly, what is the mistake?


--
If you enter this world knowing you are loved and leave this world knowing
the same, then everything that happens in between can be dealt with.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default How can I copy range's style to another in Excel?

Not used .Style before, but upon doing some research:

..Style is an Object, so at the least you would need:
Set insertedRange.Style = selectedRange.Style
However, if you read the Help, you see .Style is read-only.

If you look at the example in Excel VBA Help it show:
<Quote
Worksheets("Sheet1").Range("A1").Style.Name = "Normal"
</Quote
But this errors which #450, indicating it is read-only.

However, if you record a macro of a style change you get something like
Worksheets("Sheet1").Range("A1").Style = "Normal"

Confused ??

What is the value of
Debug.Print insertedRange.Style.Name, selectedRange.Style.Name

And what do you mean by "works not correctly" ?

NickHK

"ZeroCool127" wrote in message
...
Hi everybody,

I have a problum that I selected a range on Excel worksheet, and inserted
another range on the same worksheet, now I wanna copy the selected range's
style to the inserted one, I use

insertedRange.Style = selectedRange.Style;

or

insertedRange.Cells.Style = selectedRange.Cells.Style;

both of the two works not correctly, what is the mistake?


--
If you enter this world knowing you are loved and leave this world knowing
the same, then everything that happens in between can be dealt with.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 106
Default How can I copy range's style to another in Excel?

I don't know what is wrong eith your code but I thought of two options :

1) If you want an exact copy of the range you need the following

Range("MyRange").Copy
[navigate to the new position]
ActiveSheet.Paste
Application.CutCopyMode = False

2) If you don't want the contents but only want the formatting add the next
line to the end of the previous code

Selection.ClearContents

HTH

"ZeroCool127" wrote:

Hi everybody,

I have a problum that I selected a range on Excel worksheet, and inserted
another range on the same worksheet, now I wanna copy the selected range's
style to the inserted one, I use

insertedRange.Style = selectedRange.Style;

or

insertedRange.Cells.Style = selectedRange.Cells.Style;

both of the two works not correctly, what is the mistake?


--
If you enter this world knowing you are loved and leave this world knowing
the same, then everything that happens in between can be dealt with.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 106
Default How can I copy range's style to another in Excel?

Or if the target range already exists copy/paste only the formatting

Range("MyRange").Select
Selection.Copy
Range("MyTarget").Select
Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False

"ZeroCool127" wrote:

Hi everybody,

I have a problum that I selected a range on Excel worksheet, and inserted
another range on the same worksheet, now I wanna copy the selected range's
style to the inserted one, I use

insertedRange.Style = selectedRange.Style;

or

insertedRange.Cells.Style = selectedRange.Cells.Style;

both of the two works not correctly, what is the mistake?


--
If you enter this world knowing you are loved and leave this world knowing
the same, then everything that happens in between can be dealt with.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default How can I copy range's style to another in Excel?

Is this code in .Net or something ?
Because if it is supposed to be VBA, you do not want the ";" at the end of
the lines.

NickHK

"ZeroCool127" wrote in message
...
Hi everybody,

I have a problum that I selected a range on Excel worksheet, and inserted
another range on the same worksheet, now I wanna copy the selected range's
style to the inserted one, I use

insertedRange.Style = selectedRange.Style;

or

insertedRange.Cells.Style = selectedRange.Cells.Style;

both of the two works not correctly, what is the mistake?


--
If you enter this world knowing you are loved and leave this world knowing
the same, then everything that happens in between can be dealt with.



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
Req help on Formula or vb in excel to calculate between reference style and formula style tia sal2 temp Excel Discussion (Misc queries) 1 September 13th 07 09:02 AM
Req help on Formula or vb in excel to calculate between reference style and formula style tia sal2 temp Excel Worksheet Functions 1 September 13th 07 09:02 AM
questions regarding range's trav Excel Discussion (Misc queries) 3 February 24th 06 06:06 PM
questions regarding range's trav Excel Discussion (Misc queries) 0 February 23rd 06 11:01 PM
Range's comment text Mircea Pleteriu Excel Programming 0 January 20th 05 10:36 AM


All times are GMT +1. The time now is 07:10 PM.

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

About Us

"It's about Microsoft Excel"