LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 22,906
Default force alignment?

Art

The paste options button allows you to "match destination" formatting.

If you don't want to use that you can use VBA.

Try this event code which retains all cell formatting when something is
copy/pasted into it.

Cells must be pre-formatted to centered and centered as you state.

Private Sub Worksheet_Change(ByVal Target As Range)
Dim myValue
With Application
.EnableEvents = False
myValue = Target.Value
.Undo
Target = myValue
.EnableEvents = True
.CutCopyMode = False
End With
End Sub

This is sheet event code. Right-click on the sheet tab and "View Code".

Copy/paste the code into the module.

Operates only on the one sheet.

If you wanted for all sheets use this code which is to placed in
Thisworkbook module, not a sheet module.

Private Sub Workbook_SheetChange(ByVal Sh As _
Object, ByVal Target As Range)
Dim myValue
With Application
.EnableEvents = False
myValue = Target.Value
.Undo
Target = myValue
.EnableEvents = True
.CutCopyMode = False
End With
End Sub


Gord Dibben MS Excel MVP



On Mon, 15 Mar 2010 15:09:01 -0700, Art
wrote:

I know how to format a cell so the alignment is centered both vertically and
horizontally.

However, if a user copies/pastes text from, say, Microsoft Word into a cell
in Excel, it positiions it to the left at the bottom of the cell. Not a big
deal, really, but I would like for all of the cells to be centered
horizontally and vertically.

Is there a way to force a cell to align its contents centered, even if it is
copied and pasted from another document, rather than manually entered with a
cursor inside the cell? (Perhaps a macro could check a cell once the enter
key is pressed or the focus leaves a cell in some way?)

Thanks!


 
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
In Cell alignment, how do I update the default vertical alignment How to update default cell alignment Setting up and Configuration of Excel 2 February 4th 09 02:25 PM
Right Alignment Paul Gauci New Users to Excel 0 August 18th 08 07:33 PM
Margin Alignment aloysius Excel Discussion (Misc queries) 0 October 8th 07 07:52 PM
Need some help with alignment havocdragon Excel Discussion (Misc queries) 1 August 27th 06 01:09 PM
Alignment Leah Excel Discussion (Misc queries) 0 November 22nd 05 06:36 PM


All times are GMT +1. The time now is 01:47 AM.

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"