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. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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 | |
|
|