Using vba to format cell

warren_s

Board Regular
Joined
May 28, 2007
Messages
73
Hi
I am sure this is easy for alot of you but it is driving me nuts.
I have gotten a cell to copy from one to another and it works. Now the cell I copied to needs to be centered and bolded.
I tried the below and it will not work and I have no clue why.
If anyone knows how to do this, I would really appreciate the help.
Thank you in advance.
Warren


acivecell.Offset(1, 2).Selection.Font.Bold = True
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.

b.downey

Active Member
Joined
Oct 16, 2011
Messages
484
The "acivecell.Offset(1, 2)" line needs to be corrected to ActivateCell.


The following code may work for you

Code:
Function s()
    ActiveCell.Offset(1, 2).Select
    With Selection
         .Font.Bold = True
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlBottom
        .WrapText = False
        .Orientation = 0
        .AddIndent = False
        .IndentLevel = 0
        .ShrinkToFit = False
        .ReadingOrder = xlContext
        .MergeCells = False
    End With
End Function
 

warren_s

Board Regular
Joined
May 28, 2007
Messages
73
Thank you.
Is there anyway to do it with out the select which moves the active cell?
Warren
 

John Davis

Well-known Member
Joined
Sep 11, 2007
Messages
3,457
Hi
I am sure this is easy for alot of you but it is driving me nuts.
I have gotten a cell to copy from one to another and it works. Now the cell I copied to needs to be centered and bolded.
I tried the below and it will not work and I have no clue why.
If anyone knows how to do this, I would really appreciate the help.
Thank you in advance.
Warren


acivecell.Offset(1, 2).Selection.Font.Bold = True
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With


Perhaps:

Code:
Sub warrens()
With ActiveCell.Offset(1, 2)
    .Font.Bold = True
    .HorizontalAlignment = xlCenter
End With
End Sub
 

warren_s

Board Regular
Joined
May 28, 2007
Messages
73
Hi
I tried the below and it errored out. Below is what I came up with and it does not work also.
Any other suggestions.
Thank you.

ActiveWorkbook.Worksheets("RESULTS").Cells(COUNT, 2).Value = "Thank you"

With ActiveWorkbook.Worksheets("RESULTS").Offset(COUNT, 2)
.Selection.Font.Bold = True
.Horizonalalignment = x1Center
End With
 

John Davis

Well-known Member
Joined
Sep 11, 2007
Messages
3,457
Hi
I tried the below and it errored out. Below is what I came up with and it does not work also.
Any other suggestions.
Thank you.

ActiveWorkbook.Worksheets("RESULTS").Cells(COUNT, 2).Value = "Thank you"

With ActiveWorkbook.Worksheets("RESULTS").Offset(COUNT, 2)
.Selection.Font.Bold = True
.Horizonalalignment = x1Center
End With


Does this help?

Code:
With ActiveWorkbook.Worksheets("RESULTS").ActiveCell.Offset(1, 2)
.Font.Bold = True
.Horizonalalignment = x1Center
End With
 

Watch MrExcel Video

Forum statistics

Threads
1,129,684
Messages
5,637,790
Members
416,982
Latest member
lisam77

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
Top