VBA to select all used cells in row A only?

Human_doing

Board Regular
Joined
Feb 16, 2011
Messages
137
Hi,

Can anyone please provide the VBA to select all used cells in row A only? I have seen some great VBA on here to select all used cells on a worksheet etc. but am looking to select only row a.

Thanks
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
A few things ...

1. Rows are usually referred to by number, columns by letter. So do you mean Row 1 or Column A?

2. Selecting things in vba is rarely necessary and generally slows your code. So what are you going to do after selecting these cells? Pehaps the outcome can be achieved more efficiently without the need to select them at all.

3. Does the row/column contain constants or formulas or both?
 
Upvote 0
Hi,

Sorry to confuse, yes it is row 1 I am looking to select. What I'm trying to achieve is to select all the header cells (i.e. cells in row 1) and turn them grey as part of a wider report code,

Thanks
 
Upvote 0
Try:

Code:
Dim LC as Long
LC = Cells(1,Columns.Count).End(xlToLeft).Column
Range(Cells(1,1),Cells(1,LC)).Interior.ColorIndex = 15
 
Upvote 0
.. or if there happens to be gaps and you don't want the gaps coloured, or the headers don't start in column A then perhaps this?
Code:
Rows(1).SpecialCells(xlCellTypeConstants).Interior.ColorIndex = 15
 
Upvote 0
You could try something like this, which will only shade the cell if it has a non formula value in it.

Code:
Sub mcro()
    With ActiveSheet.Range("1:1").SpecialCells(xlCellTypeConstants)
        .Interior.ColorIndex = 15
    End With
End Sub
 
Upvote 0
Sub macFilterDuplicates()
'
' macFilterDuplicates Macro
'

'

Cells(1, 1).Select

While (Not (IsNull(ActiveCell.Value2) Or IsEmpty(ActiveCell.Value2)))
MsgBox ActiveCell.Value2
Application.CutCopyMode = False

Range(ActiveCell, Cells(Rows.Count, ActiveCell.Column).End(xlUp)).Select
Range(Selection, Selection.End(xlDown)).RemoveDuplicates Columns:=1, Header:= _
xlYes

Cells(Selection.Row, Selection.Column).Offset(, 1).Select
Wend
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,504
Messages
6,179,142
Members
452,892
Latest member
JUSTOUTOFMYREACH

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