Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 118
Default Copy format from row above for selected cells

Sub FormatasRowAbove()
Dim rng As Range
Set rng = ActiveCell
Rows(rng.Row - 1).Copy
Cells(rng.Row, 1).PasteSpecial Paste:=xlPasteFormats
Application.CutCopyMode = False
rng.Select
End Sub

How can I make above macro work for an area of cells

i.e

By selecting A2:A7 - I would like row 2 & row 7 to have same format as
row 1

Thxs

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Copy format from row above for selected cells

Hi Al007,

If your intent is to copy the formats of row 1 to the first and last rows of
the designated range, try:

'=============
Public Sub FormatasRowAbove1()
Dim rng As Range
Dim currCell As Range
Dim currRng As Range

Set currRng = Selection
Set currCell = ActiveCell
Set rng = Range("A2:A7")

Rows(rng.Row - 1).Copy
rng(1).EntireRow.PasteSpecial Paste:=xlPasteFormats
rng(rng.Count).EntireRow.PasteSpecial Paste:=xlPasteFormats
Application.CutCopyMode = False
currRng.Select
currCell.Activate

End Sub
'<<=============

If, however your intent was to copy the formats to all the rows in the
designated range, then try instead:

'=============
Public Sub FormatasRowAbove2()
Dim rng As Range
Dim currCell As Range
Dim currRng As Range

Set currRng = Selection
Set currCell = ActiveCell
Set rng = Range("A2:A7")

Rows(rng.Row - 1).Copy
rng.EntireRow.PasteSpecial Paste:=xlPasteFormats
Application.CutCopyMode = False
currRng.Select
currCell.Activate

End Sub
'<<=============


---
Regards,
Norman



"al007" wrote in message
oups.com...
Sub FormatasRowAbove()
Dim rng As Range
Set rng = ActiveCell
Rows(rng.Row - 1).Copy
Cells(rng.Row, 1).PasteSpecial Paste:=xlPasteFormats
Application.CutCopyMode = False
rng.Select
End Sub

How can I make above macro work for an area of cells

i.e

By selecting A2:A7 - I would like row 2 & row 7 to have same format as
row 1

Thxs



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 118
Default Copy format from row above for selected cells

thxs

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
Cannot copy selected cells Stevie Excel Discussion (Misc queries) 1 February 19th 10 06:06 PM
auto copy only selected cells Keith Crooks Excel Worksheet Functions 1 February 25th 06 09:42 PM
Copy Selected cells down a row with macro DB33 Excel Discussion (Misc queries) 1 February 15th 06 05:33 PM
copy selected cells to new workbook? Chimanrao Excel Programming 6 October 23rd 05 06:33 PM
Macro to format selected cells BeSmart[_2_] Excel Programming 4 May 7th 04 01:28 PM


All times are GMT +1. The time now is 07:44 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"