Assistance with formatting and adding a filter using VBA

bosko2

New Member
Joined
Nov 3, 2020
Messages
19
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
 

Some videos you may like

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.

JoeMo

MrExcel MVP
Joined
May 26, 2009
Messages
17,386
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
VBA Code:
Sub bosko2()
With Sheets("Investigations")
    .Rows(1).Font.Bold = True
    If Not .AutoFilterMode Then .Rows(1).AutoFilter
End With
End Sub
 

GWteB

Well-known Member
Joined
Sep 10, 2010
Messages
1,295
Office Version
  1. 2013
Platform
  1. Windows
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
 

bosko2

New Member
Joined
Nov 3, 2020
Messages
19
Office Version
  1. 365
Platform
  1. Windows
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?
 

JoeMo

MrExcel MVP
Joined
May 26, 2009
Messages
17,386
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
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".
 

Watch MrExcel Video

Forum statistics

Threads
1,122,351
Messages
5,595,646
Members
414,005
Latest member
BradWarr

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