ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Application defined or Object defined error (https://www.excelbanter.com/excel-programming/309268-application-defined-object-defined-error.html)

FJ Shepley & JM Pfohl

Application defined or Object defined error
 
I have two identical macros below except for the third line defining the
range is different. The first one doesn't work.
I keep getting an "Application defined or Object defined error". The
second works fine Can someone help?

First one doesn't work...

Private Sub Worksheet_Activate()
Dim ship As Range
For Each ship In Worksheets("newshipped").Range("c1",
Range("c1").End(xlRight))
If ship = "1" Then 'yesterday
ship.EntireColumn.Font.ColorIndex = 3
ship.EntireColumn.Font.Bold = False
ElseIf ship = "0" Then 'today
ship.EntireColumn.Font.ColorIndex = 1
ship.EntireColumn.Font.Bold = True
Else: ship.EntireColumn.Font.ColorIndex = 10
ship.EntireColumn.Font.Bold = False 'tomorrow
End If
Next ship
End Sub



SECOND this one works.


Private Sub Worksheet_Activate()
Dim ship As Range
For Each ship In Worksheets("shipped").Range("ak3",
Range("ak3").End(xlDown))
If ship = "1" Then 'yesterday
ship.EntireRow.Font.ColorIndex = 3
ship.EntireRow.Font.Bold = False
ElseIf ship = "0" Then 'today
ship.EntireRow.Font.ColorIndex = 1
ship.EntireRow.Font.Bold = True
Else: ship.EntireRow.Font.ColorIndex = 10
ship.EntireRow.Font.Bold = False 'tomorrow
End If
Next ship
End Sub





Norman Jones

Application defined or Object defined error
 
Hi FJ & JM,

Try changing:

xlRight

to:

:xlToRight

---
Regards,
Norman



"FJ Shepley & JM Pfohl" wrote in message
...
I have two identical macros below except for the third line defining the
range is different. The first one doesn't work.
I keep getting an "Application defined or Object defined error". The
second works fine Can someone help?

First one doesn't work...

Private Sub Worksheet_Activate()
Dim ship As Range
For Each ship In Worksheets("newshipped").Range("c1",
Range("c1").End(xlRight))
If ship = "1" Then 'yesterday
ship.EntireColumn.Font.ColorIndex = 3
ship.EntireColumn.Font.Bold = False
ElseIf ship = "0" Then 'today
ship.EntireColumn.Font.ColorIndex = 1
ship.EntireColumn.Font.Bold = True
Else: ship.EntireColumn.Font.ColorIndex = 10
ship.EntireColumn.Font.Bold = False 'tomorrow
End If
Next ship
End Sub



SECOND this one works.


Private Sub Worksheet_Activate()
Dim ship As Range
For Each ship In Worksheets("shipped").Range("ak3",
Range("ak3").End(xlDown))
If ship = "1" Then 'yesterday
ship.EntireRow.Font.ColorIndex = 3
ship.EntireRow.Font.Bold = False
ElseIf ship = "0" Then 'today
ship.EntireRow.Font.ColorIndex = 1
ship.EntireRow.Font.Bold = True
Else: ship.EntireRow.Font.ColorIndex = 10
ship.EntireRow.Font.Bold = False 'tomorrow
End If
Next ship
End Sub







FJ Shepley & JM Pfohl

Application defined or Object defined error
 
Thanks I will try tomorrow at work.
"Norman Jones" wrote in message
...
Hi FJ & JM,

Try changing:

xlRight

to:

:xlToRight

---
Regards,
Norman



"FJ Shepley & JM Pfohl" wrote in message
...
I have two identical macros below except for the third line defining the
range is different. The first one doesn't work.
I keep getting an "Application defined or Object defined error". The
second works fine Can someone help?

First one doesn't work...

Private Sub Worksheet_Activate()
Dim ship As Range
For Each ship In Worksheets("newshipped").Range("c1",
Range("c1").End(xlRight))
If ship = "1" Then 'yesterday
ship.EntireColumn.Font.ColorIndex = 3
ship.EntireColumn.Font.Bold = False
ElseIf ship = "0" Then 'today
ship.EntireColumn.Font.ColorIndex = 1
ship.EntireColumn.Font.Bold = True
Else: ship.EntireColumn.Font.ColorIndex = 10
ship.EntireColumn.Font.Bold = False 'tomorrow
End If
Next ship
End Sub



SECOND this one works.


Private Sub Worksheet_Activate()
Dim ship As Range
For Each ship In Worksheets("shipped").Range("ak3",
Range("ak3").End(xlDown))
If ship = "1" Then 'yesterday
ship.EntireRow.Font.ColorIndex = 3
ship.EntireRow.Font.Bold = False
ElseIf ship = "0" Then 'today
ship.EntireRow.Font.ColorIndex = 1
ship.EntireRow.Font.Bold = True
Else: ship.EntireRow.Font.ColorIndex = 10
ship.EntireRow.Font.Bold = False 'tomorrow
End If
Next ship
End Sub











All times are GMT +1. The time now is 02:20 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com