Can I add two "With Selections"?

mayankgo

New Member
Joined
Oct 11, 2017
Messages
10
How do I make this all in 12 lines? I don't think it is possible without adding the with selections

Code:
Range("A1").Select    With Selection.Font
        .Size = 36
    End With
    With Selection
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlCenter
    End With
    With Selection.Borders(xlEdgeBottom)
        .LineStyle = xlContinuous
    End With
    With Selection.Borders(xlEdgeRight)
        .LineStyle = xlContinuous
    End With
    With Selection.Interior
        .ThemeColor = xlThemeColorDark2
    End With
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Code:
Range("A1").Select
    With Selection
        .Font.Size = 36
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlCenter
        .Borders(xlEdgeBottom).LineStyle = xlContinuous
        .Borders(xlEdgeRight).LineStyle = xlContinuous
        .Interior.ThemeColor = xlThemeColorDark2
    End With
 
Last edited:
Upvote 0
@mumps Instead of using macro then I should learn the codes like horizontal and .font.size or is it better to trip the waste part? what do you think?
 
Upvote 0
I'm sorry but I don't quite understand what you mean. Could you please explain in more detail?
 
Upvote 0
Code:
Range("A1").Select
    With Selection
        .Font.Size = 36
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlCenter
        .Borders(xlEdgeBottom).LineStyle = xlContinuous
        .Borders(xlEdgeRight).LineStyle = xlContinuous
        .Interior.ThemeColor = xlThemeColorDark2
    End With
Actually, there is no reason to select cell A1 in order to work with it...
Code:
With Range("A1")
  .Font.Size = 36
  .HorizontalAlignment = xlCenter
  .VerticalAlignment = xlCenter
  .Borders(xlEdgeBottom).LineStyle = xlContinuous
  .Borders(xlEdgeRight).LineStyle = xlContinuous
  .Interior.ThemeColor = xlThemeColorDark2
End With
 
Last edited:
Upvote 0
I'm new to Excel VBA. Which one is preferable either I should use a macro to record and then trim the waste part or should I learn the edit codes?

Thank you to Rick too :)
 
Upvote 0
If you use the macro recorder, then that recorded macro will work only for that very specific task or situation. It is not at all flexible. That doesn't mean that recorded macros are not useful. They can save much time when typing lines of code. You can then edit the macro to become more flexible so it can be used in varying situations.
 
Upvote 0
I'm new to Excel VBA. Which one is preferable either I should use a macro to record and then trim the waste part or should I learn the edit codes?
I think you will find programming more flexible if you learn to write code yourself. That does not mean the macro recorder is worthless... I still use it when I need to code something I am not familiar with... it gives me an overall structure for the operation I am not sure of which I can then recode (eliminating all the excess or inefficient stuff it produces) and then incorporate into the overall code that I am writing.
 
Upvote 0

Forum statistics

Threads
1,215,335
Messages
6,124,326
Members
449,155
Latest member
ravioli44

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top