A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Excel » Worksheet Functions
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

force alignment?



 
 
Thread Tools Display Modes
  #1  
Old March 15th, 2010, 11:09 PM posted to microsoft.public.excel.worksheet.functions
ART
external usenet poster
 
Posts: 432
Default force alignment?

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!
  #2  
Old March 16th, 2010, 12:22 AM posted to microsoft.public.excel.worksheet.functions
Gord Dibben
external usenet poster
 
Posts: 20,252
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!


  #3  
Old March 16th, 2010, 03:55 PM posted to microsoft.public.excel.worksheet.functions
ART
external usenet poster
 
Posts: 432
Default force alignment?

To start, I pasted the code just in the sheet. However, when I copied/pasted
text from Word then moved to another cell, it didn't keep the formatting. I
was very excited about this working...am I missing something?

Thanks for the work...and look forward to hearing back from you!!!




"Gord Dibben" wrote:

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!


.

  #4  
Old March 16th, 2010, 03:58 PM posted to microsoft.public.excel.worksheet.functions
ART
external usenet poster
 
Posts: 432
Default force alignment?

Does this matter:

When a user pastes text from Word into the cell in Excel, they aren't
double-clicking in the cell. They click/select the cell, then paste (usually
CTRL-V). I don't have a problem with formatting being maintained if the user
double-clicks in the cell first, but this doesn't usually happen.

Will the VBA you suggested work if users do not double-click in the cell
(giving them a cursor)?



"Gord Dibben" wrote:

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!


.

  #5  
Old March 16th, 2010, 05:56 PM posted to microsoft.public.excel.worksheet.functions
Gord Dibben
external usenet poster
 
Posts: 20,252
Default force alignment?

I have tested by copying strings of text from a Word document.

Back to Excel and paste into a cell.

Alignment stayed as Center/Center as I had originally formatted.

What do you mean by "moved to another cell"?


Gord

On Tue, 16 Mar 2010 07:55:01 -0700, Art
wrote:

To start, I pasted the code just in the sheet. However, when I copied/pasted
text from Word then moved to another cell, it didn't keep the formatting. I
was very excited about this working...am I missing something?

Thanks for the work...and look forward to hearing back from you!!!




"Gord Dibben" wrote:

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!


.


  #6  
Old March 16th, 2010, 06:02 PM posted to microsoft.public.excel.worksheet.functions
Gord Dibben
external usenet poster
 
Posts: 20,252
Default force alignment?

Double-clicking on the cell puts the user into edit mode and they are
essentially pasting into the formula bar.

Either method of pasting works for me.

I rarely use the double-click and paste.

I generally paste directly to the cell. CTRL + V or EditPaste or just hit
Paste button.


Gord


On Tue, 16 Mar 2010 07:58:04 -0700, Art
wrote:

Does this matter:

When a user pastes text from Word into the cell in Excel, they aren't
double-clicking in the cell. They click/select the cell, then paste (usually
CTRL-V). I don't have a problem with formatting being maintained if the user
double-clicks in the cell first, but this doesn't usually happen.

Will the VBA you suggested work if users do not double-click in the cell
(giving them a cursor)?



"Gord Dibben" wrote:

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!


.


  #7  
Old March 17th, 2010, 12:18 AM posted to microsoft.public.excel.worksheet.functions
ART
external usenet poster
 
Posts: 432
Default force alignment?

Either use the TAB key or press the enter key.

"Gord Dibben" wrote:

I have tested by copying strings of text from a Word document.

Back to Excel and paste into a cell.

Alignment stayed as Center/Center as I had originally formatted.

What do you mean by "moved to another cell"?


Gord

On Tue, 16 Mar 2010 07:55:01 -0700, Art
wrote:

To start, I pasted the code just in the sheet. However, when I copied/pasted
text from Word then moved to another cell, it didn't keep the formatting. I
was very excited about this working...am I missing something?

Thanks for the work...and look forward to hearing back from you!!!




"Gord Dibben" wrote:

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!

.


.

  #8  
Old March 17th, 2010, 12:54 AM posted to microsoft.public.excel.worksheet.functions
Gord Dibben
external usenet poster
 
Posts: 20,252
Default force alignment?

If you want to email me the workbook I'll have a look.

gorddibbATshawDOTca change the obvious.


Gord

On Tue, 16 Mar 2010 16:18:01 -0700, Art
wrote:

Either use the TAB key or press the enter key.

"Gord Dibben" wrote:

I have tested by copying strings of text from a Word document.

Back to Excel and paste into a cell.

Alignment stayed as Center/Center as I had originally formatted.

What do you mean by "moved to another cell"?


Gord

On Tue, 16 Mar 2010 07:55:01 -0700, Art
wrote:

To start, I pasted the code just in the sheet. However, when I copied/pasted
text from Word then moved to another cell, it didn't keep the formatting. I
was very excited about this working...am I missing something?

Thanks for the work...and look forward to hearing back from you!!!




"Gord Dibben" wrote:

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
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 09:21 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.