Find Last Column, Select, and Bold

  • Thread starter Thread starter Yellowbird
  • Start date Start date
Y

Yellowbird

I don't know much about VBA - I usually search for snippets of code
that do what I want and then modify them as necessary. This seems to
work alright for my needs, but then I get stuck on something that
seems like it should be so obvious.

Here's (hopefully) an easy one:

I have a variable number of rows and columns in my spreadsheet. I need
to be able to search for the last column with data in it, select that
column, and then make all text bold, and the same for the last row
with data in it.

I'm able to do this successfully for my last row with:

ActiveSheet.Cells(ActiveSheet.Cells(Rows.Count,
"A").End(xlUp).Row, 1).Activate
Selection.EntireRow.Font.Bold = True

However, when I change "row" to "column" and "xlUp" to "xlToLeft", I
get an error 424.

ActiveSheet.Cells(ActiveSheet.Cells(Column.Count,
"A").End(xlToLeft).Column, 1).Activate
Selection.EntireColumn.Font.Bold = True

I'm sure I'm missing something fairly obvious, but would appreciate
any pointers.

TIA,
Yellowbird
 
Hi Yellowbird

Sub MakeBold()
With ActiveSheet
..Cells.Font.Bold = False
..Range("IV1").End(xlToLeft).EntireColumn.Font.Bold = True
..Range("A" & Rows.Count).End(xlUp).EntireRow.Font.Bold = True
End With
End Sub

[Assumes Column A and Row 1 contain the last cells that would apply to all
columns and rows]

--
XL2002
Regards

William

(e-mail address removed)

| I don't know much about VBA - I usually search for snippets of code
| that do what I want and then modify them as necessary. This seems to
| work alright for my needs, but then I get stuck on something that
| seems like it should be so obvious.
|
| Here's (hopefully) an easy one:
|
| I have a variable number of rows and columns in my spreadsheet. I need
| to be able to search for the last column with data in it, select that
| column, and then make all text bold, and the same for the last row
| with data in it.
|
| I'm able to do this successfully for my last row with:
|
| ActiveSheet.Cells(ActiveSheet.Cells(Rows.Count,
| "A").End(xlUp).Row, 1).Activate
| Selection.EntireRow.Font.Bold = True
|
| However, when I change "row" to "column" and "xlUp" to "xlToLeft", I
| get an error 424.
|
| ActiveSheet.Cells(ActiveSheet.Cells(Column.Count,
| "A").End(xlToLeft).Column, 1).Activate
| Selection.EntireColumn.Font.Bold = True
|
| I'm sure I'm missing something fairly obvious, but would appreciate
| any pointers.
|
| TIA,
| Yellowbird
 
William provided a good solution - as to your problem, you replaced
rows.count with columns.count, but it is being supplied as the rows argument
and the column remains "A". So you would need to do this:

ActiveSheet.Cells(1,ActiveSheet.Cells(1,Columns. _
Count).End(xlToLeft).Column).Activate
Selection.EntireColumn.Font.Bold = True
 
Thanks for the clarification, William.

That did the trick. My data starts in row 2, so once I changed the
"IV" value to "IV2", everything worked as expected.

Yellowbird
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top