am i missing something in code?

bhandari

Active Member
Joined
Oct 17, 2017
Messages
359
Code:
Sub ThirdClass()
Dim Finalrow As Long
i As Double
Finalrow = cells(65536, 1).End(xlUp).Row
For i = 1 To Finalrow
cells(1, 1).Resize(, 5).Font.Bold = True
Next i
End Sub
error=statement invalid outside type block
i want 5th column text=bold
 
Last edited:
Thank You @hiker95

can u please check #6
i want to use that code to get the output

Bhandari,

Try the following:

Code:
Sub ThirdClass_V3()
' hiker95, 10/28/2017, ME1029086
Dim Finalrow As Long
Dim i As Long
Finalrow = Cells(65536, 1).End(xlUp).Row
For i = 1 To Finalrow
  Cells(i, 1).Resize(, 5).Font.Bold = True
Next i
End Sub
 
Upvote 0

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Hiker95 has shown you in post number 11 how to loop through the range.

If you want to use the range rather than cells without looping it is

Code:
Sub ThirdClass()
Dim Finalrow As Long
Finalrow = Cells(Rows.Count, 1).End(xlUp).Row

Range("A1" & ":E" & Finalrow).Font.Bold = True

End Sub

or

Code:
Sub ThirdClass2()
Dim Finalrow As Long
Finalrow = Cells(Rows.Count, 1).End(xlUp).Row

Range("A1").Resize(Finalrow, 5).Font.Bold = True

End Sub

although the 2nd code is more inefficient than the 1st
 
Last edited:
Upvote 0
Bhandari,

One more try:

Code:
Sub ThirdClass_V4()
' hiker95, 10/28/2017, ME1029086
Dim Finalrow As Long
Finalrow = Columns("A:E").Find(What:="*", SearchDirection:=xlPrevious, SearchOrder:=xlByRows).Row
Range("A1:E" & Finalrow).Font.Bold = True
End Sub
 
Upvote 0
Bhandari,

Thanks for the feedback.

You are very welcome. Glad we could help.

And, come back anytime.
 
Upvote 0
Just to complete my postings...

Code:
Sub ThirdClass4()
Range("A1:E" & Range("A" & Rows.Count).End(xlUp).Row).Font.Bold = True
End Sub
or
Code:
Sub ThirdClass5()
Range("A1:E" & Columns("A:E").Find("*", , xlValues, , xlByRows, xlPrevious).Row).Font.Bold = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,824
Messages
6,181,186
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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