If your data is in column A, starting in row 1, this code will color each row blue if there is a number within the value in column A:
Code:
Sub colorRow()
Dim i As Long
Dim j As Long
Dim LR As Long
Dim charCount As Integer
LR = Range("a" & Rows.Count).End(xlUp).Row
For i = 1 To LR
charCount = Len(Range("a" & i).Value)
For j = 1 To charCount
If IsNumeric(Mid(Range("a" & i).Value, j, 1)) Then
Range("a" & i).EntireRow.Interior.Color = vbBlue
GoTo BailOut
End If
Next j
BailOut:
Next i
End Sub
Ohh That's a great MAcro and almost what I need Hope you could help?
Would it be possible to ad something to this?
I would like to ad the folowing as now when Collum K has a value then the row turns green.
In adition to this I need rows to be turned Blue when the row in collum K and M both contain a numeric value.
Could you help me with this?
Sub colorRow()
Dim i As Long
Dim j As Long
Dim LR As Long
Dim charCount As Integer
LR = Range("k" & Rows.Count).End(xlUp).Row
For i = 1 To LR
charCount = Len(Range("k" & i).Value)
For j = 1 To charCount
If IsNumeric(Mid(Range("k" & i).Value, j, 1)) Then
Range("k" & i).EntireRow.Interior.Color = vbGreen
GoTo BailOut
End If
Next j
BailOut:
Next i
Ohh That's a great MAcro and almost what I need Hope you could help?
Would it be possible to ad something to this?
I would like to ad the folowing as now when Collum K has a value then the row turns green.
In adition to this I need the row to be turned Blue when in collum K and M both contain a numeric value on the same row.
Could you help me with this?
Sub colorRow()
Dim i As Long
Dim j As Long
Dim LR As Long
Dim charCount As Integer
LR = Range("k" & Rows.Count).End(xlUp).Row
For i = 1 To LR
charCount = Len(Range("k" & i).Value)
For j = 1 To charCount
If IsNumeric(Mid(Range("k" & i).Value, j, 1)) Then
Range("k" & i).EntireRow.Interior.Color = vbGreen
GoTo BailOut
End If
Next j
BailOut:
Next i
Re: [RESOLVED] (VBA) Color row if cell contains a number
something like this:
Code:
Sub colorRows()
Dim i As Long
'Dim j As Long
Dim lrK As Long 'last row with a filled cell in column K
Dim lrM As Long 'last row with a filled cell in column M
Dim lr As Long 'max of lrK and lrM
Dim ws As Worksheet
Set ws = ActiveSheet
lrK = Range("k" & Rows.Count).End(xlUp).Row
lrM = Range("m" & Rows.Count).End(xlUp).Row
lr = Application.WorksheetFunction.Max(lrK, lrM)
For i = 1 To lr 'my data starts in row 1, otherwise change this
If IsNumeric(ws.Range("k" & i).Value) Then
If IsNumeric(ws.Range("m" & i).Value) Then
'both K and M have a numeric value, so BLUE
ws.Range("a" & i).EntireRow.Interior.Color = vbBlue
Else
'only K is numeric
ws.Range("a" & i).EntireRow.Interior.Color = vbGreen
End If
End If
Next i
End Sub
Re: [RESOLVED] (VBA) Color row if cell contains a number
Originally Posted by vbfbryce
something like this:
Code:
Sub colorRows()
Dim i As Long
'Dim j As Long
Dim lrK As Long 'last row with a filled cell in column K
Dim lrM As Long 'last row with a filled cell in column M
Dim lr As Long 'max of lrK and lrM
Dim ws As Worksheet
Set ws = ActiveSheet
lrK = Range("k" & Rows.Count).End(xlUp).Row
lrM = Range("m" & Rows.Count).End(xlUp).Row
lr = Application.WorksheetFunction.Max(lrK, lrM)
For i = 1 To lr 'my data starts in row 1, otherwise change this
If IsNumeric(ws.Range("k" & i).Value) Then
If IsNumeric(ws.Range("m" & i).Value) Then
'both K and M have a numeric value, so BLUE
ws.Range("a" & i).EntireRow.Interior.Color = vbBlue
Else
'only K is numeric
ws.Range("a" & i).EntireRow.Interior.Color = vbGreen
End If
End If
Next i
End Sub
Not sure why it wouldn't work. below the info in the collums it doesn't color any collums it doesn't seem to run.
Can I give you aditional info to work this out?
Collum K Collum L Colloum M
On Hand date First possible Delivery Date Delivered on
2013-09-05 14:10:00
2013-09-06 14:12:00 2013-09-10 08:52:00
2013-09-06 16:02:00 2013-09-10 08:52:00
2013-09-08 15:56:00 2013-09-10 08:52:00
2013-09-12 09:00:00
Re: [RESOLVED] (VBA) Color row if cell contains a number
If you're looking for dates in those columns, change to IsDate, like this:
Code:
Sub colorRows()
Dim i As Long
Dim lrK As Long 'last row with a filled cell in column K
Dim lrM As Long 'last row with a filled cell in column M
Dim lr As Long 'max of lrK and lrM
Dim ws As Worksheet
Set ws = ActiveSheet
lrK = Range("k" & Rows.Count).End(xlUp).Row
lrM = Range("m" & Rows.Count).End(xlUp).Row
lr = Application.WorksheetFunction.Max(lrK, lrM)
For i = 2 To lr 'my data starts in row 1, otherwise change this
If IsDate(ws.Range("k" & i).Value) Then
If IsDate(ws.Range("m" & i).Value) Then
'both K and M have a date value, so BLUE
ws.Range("a" & i).EntireRow.Interior.Color = vbBlue
Else
'only K is date
ws.Range("a" & i).EntireRow.Interior.Color = vbGreen
End If
End If
Next i
End Sub
In your example, they would all be green. None would be blue since there are no dates in column M.
Re: [RESOLVED] (VBA) Color row if cell contains a number
Hi Bryce,
Good stuff this, one more question I've tried change the color of the green to light gray is that posible?
Or can I only use the VB colors. I also tried the excel ones but didn't work.
Re: [RESOLVED] (VBA) Color row if cell contains a number
Hello Bryce,
Don't now how to start a ne thread or if I need to.
This is how the code is now and need to ad on more thing. As an addition in this script I need borders on the rows wich are active. In this case it needs to start in the second row and until the last row wich contains data. I've had a look around but this is out of my league. Can you help? When you look at the pic below in needs to look like this..This is how the script is now:
Sub Bestio_Daily()
' runs macro for Bestio daily report
Application.ScreenUpdating = False
Dim i As Long
Dim lrK As Long 'last row with a filled cell in column K
Dim lrM As Long 'last row with a filled cell in column M
Dim lr As Long 'max of lrK and lrM
Dim ws As Worksheet
For i = 2 To lr 'my data starts in row 1, otherwise change this
If IsDate(ws.Range("k" & i).Value) Then
If IsDate(ws.Range("m" & i).Value) Then
'both K and M have a date value, so BLUE
ws.Range("a" & i).EntireRow.Interior.ColorIndex = 50
Else
'only K is date
ws.Range("a" & i).EntireRow.Interior.Color = RGB(192, 192, 192)
End If
End If
Next i
Re: [RESOLVED] (VBA) Color row if cell contains a number
add something like this after you do the "coloring:"
Code:
With ws.Range("a2:m" & lr).BorderAround 'change M to whatever your last column is
.LineStyle = xlContinuous
.ColorIndex = xlAutomatic
.TintAndShade = 0
.Weight = xlThin
End With
Re: [RESOLVED] (VBA) Color row if cell contains a number
Hello Bryce,
Thanks for the last code.
I want to start en new thread but don't know how.
I'm looking for a piece of code that wil scan a column and when it comes on a blank cell or empty cell it wil copy the cel on the right and pastes it in the blank cell and then continiues.
Hope you could help or let me know how to start a new post?