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

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
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
 
Upvote 0
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
 
Upvote 0
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
 
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,213,510
Messages
6,114,037
Members
448,543
Latest member
MartinLarkin

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