PC Review


Reply
Thread Tools Rate Thread

APPLY A CELL's FORMAT WITHOUT SELECTING

 
 
Faraz A. Qureshi
Guest
Posts: n/a
 
      22nd Dec 2009
Any idea how to have a cell(s) for example A1:A10 acquire the exact format as
of B1 without copy, selecting & pasting special xlPasteFormats?
--
Thanx in advance,
Best Regards,

Faraz
 
Reply With Quote
 
 
 
 
Rick Rothstein
Guest
Posts: n/a
 
      22nd Dec 2009
This macro will do that...

Sub CopyB1sFormat()
Dim V As Variant, Ra As Range, Rb As Range
Set Ra = Range("A1:A10")
Set Rb = Range("B1")
V = Join(WorksheetFunction.Transpose(Ra.Value), Chr$(1))
Rb.Copy Ra
Ra = WorksheetFunction.Transpose(Split(V, Chr$(1)))
End Sub

--
Rick (MVP - Excel)


"Faraz A. Qureshi" <(E-Mail Removed)> wrote in
message news:6207F8C3-6AA2-4189-9850-(E-Mail Removed)...
> Any idea how to have a cell(s) for example A1:A10 acquire the exact format
> as
> of B1 without copy, selecting & pasting special xlPasteFormats?
> --
> Thanx in advance,
> Best Regards,
>
> Faraz


 
Reply With Quote
 
Faraz A. Qureshi
Guest
Posts: n/a
 
      22nd Dec 2009
WOW!
XClent!
Thanx a lot a pal!
Really did off-load a burden!

However would u kindly interpret the code?
--
Thanx in advance,
Best Regards,

Faraz


"Rick Rothstein" wrote:

> This macro will do that...
>
> Sub CopyB1sFormat()
> Dim V As Variant, Ra As Range, Rb As Range
> Set Ra = Range("A1:A10")
> Set Rb = Range("B1")
> V = Join(WorksheetFunction.Transpose(Ra.Value), Chr$(1))
> Rb.Copy Ra
> Ra = WorksheetFunction.Transpose(Split(V, Chr$(1)))
> End Sub
>
> --
> Rick (MVP - Excel)
>
>
> "Faraz A. Qureshi" <(E-Mail Removed)> wrote in
> message news:6207F8C3-6AA2-4189-9850-(E-Mail Removed)...
> > Any idea how to have a cell(s) for example A1:A10 acquire the exact format
> > as
> > of B1 without copy, selecting & pasting special xlPasteFormats?
> > --
> > Thanx in advance,
> > Best Regards,
> >
> > Faraz

>
> .
>

 
Reply With Quote
 
Rick Rothstein
Guest
Posts: n/a
 
      22nd Dec 2009
Here is the same code I posted along with comments explaining what is going
on. The main thrust of the code is to protect the original values in the
cells having their format changed (because the Copy operation will overwrite
them).

Sub CopyB1sFormat()
' Declare variable
Dim V As Variant, Ra As Range, Rb As Range
' Assign the destination range
Set Ra = Range("A1:A10")
' Assign the source cell to use for the formatting
Set Rb = Range("B1")
' Copy existing values from the destination cells into a string...
' Transpose takes a contiguous **column** of cells and creates a
' one-dimensional array from them which the Join function can then
' operate on... the Chr$(1) is just a delimiter character... any
' character can be use, but that character should never be able to
' appear in the text of any cell being joined (otherwise Split'ting
' them apart later will be impossible to do... Chr$(1) is a just
' a non-typable character that can't (under normal circumstances)
' appear in text string.
V = Join(WorksheetFunction.Transpose(Ra.Value), Chr$(1))
' Copy the contents and formatting from the source cell into the
' destination cell
Rb.Copy Ra
' Put the original values that were in the source cells back into
' the source cells. Split creates a one-dimensional array from the
' text string stored in V and the Transpose function puts it back
' into a form that can be assign to a range of cells.
Ra = WorksheetFunction.Transpose(Split(V, Chr$(1)))
End Sub

--
Rick (MVP - Excel)


"Faraz A. Qureshi" <(E-Mail Removed)> wrote in
message news:912C523D-4C19-4BB7-BC65-(E-Mail Removed)...
> WOW!
> XClent!
> Thanx a lot a pal!
> Really did off-load a burden!
>
> However would u kindly interpret the code?
> --
> Thanx in advance,
> Best Regards,
>
> Faraz
>
>
> "Rick Rothstein" wrote:
>
>> This macro will do that...
>>
>> Sub CopyB1sFormat()
>> Dim V As Variant, Ra As Range, Rb As Range
>> Set Ra = Range("A1:A10")
>> Set Rb = Range("B1")
>> V = Join(WorksheetFunction.Transpose(Ra.Value), Chr$(1))
>> Rb.Copy Ra
>> Ra = WorksheetFunction.Transpose(Split(V, Chr$(1)))
>> End Sub
>>
>> --
>> Rick (MVP - Excel)
>>
>>
>> "Faraz A. Qureshi" <(E-Mail Removed)> wrote in
>> message news:6207F8C3-6AA2-4189-9850-(E-Mail Removed)...
>> > Any idea how to have a cell(s) for example A1:A10 acquire the exact
>> > format
>> > as
>> > of B1 without copy, selecting & pasting special xlPasteFormats?
>> > --
>> > Thanx in advance,
>> > Best Regards,
>> >
>> > Faraz

>>
>> .
>>


 
Reply With Quote
 
 
 
Reply

« Countif | Hyperlink »
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
Split a cell diagonally and apply a different conditional format. Champ Microsoft Excel Worksheet Functions 2 5th Feb 2009 06:38 PM
How to apply same format of referenced cell in Excel =?Utf-8?B?U3RldmVuIEJyYXNzZW0=?= Microsoft Excel Misc 0 21st Sep 2006 01:14 PM
Selecting only a certain format of cell =?Utf-8?B?Y2Ri?= Microsoft Access 5 1st Feb 2005 05:33 PM
Excel doesn't apply the cell format miniwizard Microsoft Excel Misc 2 15th Jan 2004 08:50 AM
Cant apply format currency to a cell. Mario Microsoft Excel Misc 1 21st Aug 2003 10:49 PM


Features
 

Advertising
 

Newsgroups
 


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