Instruct to start in Row 5

S

Steved

Hello from Steved

Please how do I start the below form Row 5, I Thanyou in advance.

Sub Underline4thDigit()
Dim myS As String
Dim myD As Range

For Each myD In Intersect(ActiveSheet.UsedRange, Range("D:D"))
myS = myD.Value
myD.NumberFormat = "@"
myD.Value = myS
With myD.Characters(Start:=4, Length:=1).Font
.FontStyle = "Bold"
.Color = -16776961
.Underline = xlUnderlineStyleSingle
End With
Next myD
End Sub
 
T

The Code Cage Team

This should do it for you!


Code:
--------------------
Sub Underline4thDigit()
Dim myS As String
Dim myD As Range

For Each myD In Intersect(ActiveSheet.UsedRange, Range("D5:D" & Range("D" & rows.count).end(xlup).row))
myS = myD.Value
myD.NumberFormat = "@"
myD.Value = myS
With myD.Characters(Start:=4, Length:=1).Font
.FontStyle = "Bold"
.Color = -16776961
.Underline = xlUnderlineStyleSingle
End With
Next myD
End Sub
--------------------


--
The Code Cage Team

Regards,
The Code Cage Team
'The Code Cage' (http://www.thecodecage.com)
 
C

Chip Pearson

Steved,

Try code like the following

Dim RR As Range
Dim R As Range
Dim WS As Worksheet
Set WS = ActiveSheet
With WS
Set RR = Application.Intersect(.UsedRange, _
.Range(.Cells(5, "D"), .Cells(.Rows.Count, "D")))
End With

For Each R In RR.Cells
' do something
Next R


Cordially,
Chip Pearson
Microsoft MVP
Excel Product Group
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)
 
C

Chip Pearson

Depending on the data content, that code may miss some lines at the
bottom of the data. For example, if the data goes down to row 100 but
the last non-blank element in column D is at 80, rows 81->100 won't be
processed. This may or may not be relevant to the problem at hand.

Cordially,
Chip Pearson
Microsoft MVP
Excel Product Group
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)
 
S

Steved

Hello Chip from Steved

Chip I run the below and it is not underling the 4th Digit also it is not
changing the 4th digit to bold and Red. Yes I inserted it into a module I
also did a view code insert. To my thinking I've forgotten to do something.
Thankyou.


Sub Underline4thDigit()
Dim RR As Range
Dim R As Range
Dim WS As Worksheet
Set WS = ActiveSheet
With WS
Set RR = Application.Intersect(.UsedRange, _
.Range(.Cells(5, "D"), .Cells(.Rows.Count, "D")))
End With

For Each R In RR.Cells
With R.Characters(Start:=4, Length:=1).Font
.FontStyle = "Bold"
.Color = -16776961
.Underline = xlUnderlineStyleSingle
End With
Next R
End Sub
 
S

Steved

Hello from Steved

my Fault it does work if it is 2442 but if it is 0042 it cut's of the "00"
how can I avoid this please.
 

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

Top