Assistance with formatting and adding a filter using VBA

bosko2

New Member
Joined
Nov 3, 2020
Messages
22
Office Version
  1. 365
Platform
  1. Windows
Hi all fellow Excelers!

I need a helping hand with some VBA specifically relating to formatting a new sheet that has been created. I would like the top row to be bold and have a simple filter applied, see the below section of the script where I've been attempting it:

VBA Code:
Sheets("Investigations").Select
ActiveWindow.SelectedSheets.Visible = False
Selection.AutoFilter
Selection.WrapText = True
Selection.HorizontalAlignment = xlLeft
Selection.VerticalAlignment = xlVAlignTop

I've been able to text wrap the text in each cell and sort the horizontal and vertical alignment, I just can't make row 1 bold and apply filter to row 1. The sheet that the data comes from is titled "Investigations", and based on some user inputs, it copies it to a new sheet titled "My Investigations"

Any assistance would be awesome!

Cheers,
Mike
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
VBA Code:
Sub bosko2()
With Sheets("Investigations")
    .Rows(1).Font.Bold = True
    If Not .AutoFilterMode Then .Rows(1).AutoFilter
End With
End Sub
 
Upvote 0
VBA Code:
Sub bosko2()
    Dim r As Range
    With ThisWorkbook.Worksheets("Investigations")
        Set r = Range(.Cells(1, 1), .Cells(1, .Cells(1, .Columns.Count).End(xlToLeft).Column))
    End With
    r.Font.Bold = True
    r.Parent.AutoFilterMode = False
    r.AutoFilter
End Sub
 
Upvote 0
VBA Code:
Sub bosko2()
With Sheets("Investigations")
    .Rows(1).Font.Bold = True
    If Not .AutoFilterMode Then .Rows(1).AutoFilter
End With
End Sub
Hey JoeMo:

Thank you for the code, where would I place it in the above part of my script?
 
Upvote 0
Hey JoeMo:

Thank you for the code, where would I place it in the above part of my script?
It's a standalone With - End With block that will bolden and apply filter dropdowns to row 1 of the worksheet "Investigations".
 
Upvote 0

Forum statistics

Threads
1,213,551
Messages
6,114,266
Members
448,558
Latest member
aivin

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