View Full Version : Macro to format 2 cells adjacent to each other
namy77
09-23-2016, 06:20 AM
Hi guys, I am trying to format text in 2 columns next to each other.
From: 17145
to: 17146
Font size = 10, Realign left cell.
Would it be possible to adjust formatting for these cells only? As you can notice the text above is unchanged.
It is also possible to have more than 2 lines - but formatting requirements are the same. Thanks!
Record a Macro, then you can call it with hot keys or fro the menu.
First Select the cells, then record the Macro.
If you post the recorded code here, we wll help you Perfect it.
namy77
09-23-2016, 07:40 AM
Record a Macro, then you can call it with hot keys or fro the menu.
First Select the cells, then record the Macro.
If you post the recorded code here, we wll help you Perfect it.
This is what I have
Sub Macro1()'
' Macro1 Macro
'
'
With Selection.Font
.Name = "Arial"
.Size = 10
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = xlAutomatic
.TintAndShade = 0
.ThemeFont = xlThemeFontNone
End With
Range("B16:E17").Select
With Selection
.HorizontalAlignment = xlRight
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
End With
Range("F19:I19").Select
End Sub
Thanks!
Sub Macro1()'
' Macro1 Macro
'
With Selection.Font
.Name = "Arial"
.Size = 10
End With
Selection.Columns(1).HorizontalAlignment = xlRight
End Sub
I am sure there is a way to assign hotkeys to existing Sub Procedures, but I don't know it.
Record another macro and give it a name like
Format_Font10_AlignRight
It is important to use well constructed Macro names to tell what the macro will do. If you were to have several macros with names like Macro1, Macro2, Macro3, etc, You won't remember them all.
Type at least one character in the recording so the macro will save, then replace the code in that macro with the code above. Then you can delete Macro1
namy77
09-23-2016, 09:59 AM
Sub Macro1()'
' Macro1 Macro
'
With Selection.Font
.Name = "Arial"
.Size = 10
End With
Selection.Columns(1).HorizontalAlignment = xlRight
End Sub
I am sure there is a way to assign hotkeys to existing Sub Procedures, but I don't know it.
Record another macro and give it a name like
Format_Font10_AlignRight
It is important to use well constructed Macro names to tell what the macro will do. If you were to have several macros with names like Macro1, Macro2, Macro3, etc, You won't remember them all.
Type at least one character in the recording so the macro will save, then replace the code in that macro with the code above. Then you can delete Macro1
It seems to merge the first column's cells altogether.
Impossible.
Widen the column and Heighten the Rows and see what happens.
jdautel
09-23-2016, 02:19 PM
to assign a hotkey to an existing module just open up your macros, find the module, click options, then you can assign a hotkey
jdautel,
Which version of Excel? I don't see that in 2002.
Also, I'm not sure what you mean when you say, "assign a hotkey to an existing module," because a Module is a container, not a Procedure.
When you say, "open up your macros," do you mean to open the VBA Editor?
Then you say, "find the module"
All in all I think you mean "Macro" when you say, "Module."
jdautel
09-26-2016, 06:24 AM
yeah sorry:
1. Click developer tab
2. Click macros
3. select the desired procedure
4. Click Options...
(You can find it right underneath the delete button)
5. Choose a hotkey.
Click developer tab Excel >= 2007
Thanks.
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.