ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Object Defined error (https://www.excelbanter.com/excel-programming/343060-object-defined-error.html)

davegb

Object Defined error
 
This code:

Sub CountReasonContactCode()
Dim Wksht As Worksheet
Dim rReason As Range
Dim lRow As Long
Dim lCurRow As Long
Dim rCell As Range
Dim l16Rct As Long
Dim l16Act As Long
Dim l16BGct As Long
Dim lCt As Long
Dim lTotNameRow As Long



lRow = 107
lTotNameRow = 4
l16Rct = 0
l16Act = 0
l16BGct = 0

For Each Wksht In ThisWorkbook.Worksheets


Set rReason = ActiveSheet.Range("D8", Cells(lRow, "D"))

For Each rCell In rReason
If rCell = "16" Then

lCt = InStr(1, UCase(rCell.Offset(0, 2).Value), "R")
If lCt 0 Then
l16Rct = l16Rct + 1
lCt = 0
End If

lCt = InStr(1, UCase(rCell.Offset(0, 2).Value), "A")
If lCt 0 Then
l16Act = l16Act + 1
lCt = 0
End If

lCt = InStr(1, UCase(rCell.Offset(0, 2)).Value, "B")
If lCt 0 Then
l16BGct = l16BGct + 1
Else
lCt = InStr(1, UCase(rCell.Offset(0, 2)).Value, "G")
If lCt 0 Then
l16BGct = l16BGct + 1
lCt = 0
End If

End If
End If
With Worksheets("Totals")
.Range("G", lTotNameRow) = l16Rct<----ERROR

gives me an "Object Defined" error at the marked line. Any ideas?
Thanks!


Bob Phillips[_6_]

Object Defined error
 
Maybe try

.Range("G" & lTotNameRow) = l16Rct

or

.Cells(lTotNameRow, "G") = l16Rct

--

HTH

RP
(remove nothere from the email address if mailing direct)


"davegb" wrote in message
oups.com...
This code:

Sub CountReasonContactCode()
Dim Wksht As Worksheet
Dim rReason As Range
Dim lRow As Long
Dim lCurRow As Long
Dim rCell As Range
Dim l16Rct As Long
Dim l16Act As Long
Dim l16BGct As Long
Dim lCt As Long
Dim lTotNameRow As Long



lRow = 107
lTotNameRow = 4
l16Rct = 0
l16Act = 0
l16BGct = 0

For Each Wksht In ThisWorkbook.Worksheets


Set rReason = ActiveSheet.Range("D8", Cells(lRow, "D"))

For Each rCell In rReason
If rCell = "16" Then

lCt = InStr(1, UCase(rCell.Offset(0, 2).Value), "R")
If lCt 0 Then
l16Rct = l16Rct + 1
lCt = 0
End If

lCt = InStr(1, UCase(rCell.Offset(0, 2).Value), "A")
If lCt 0 Then
l16Act = l16Act + 1
lCt = 0
End If

lCt = InStr(1, UCase(rCell.Offset(0, 2)).Value, "B")
If lCt 0 Then
l16BGct = l16BGct + 1
Else
lCt = InStr(1, UCase(rCell.Offset(0, 2)).Value, "G")
If lCt 0 Then
l16BGct = l16BGct + 1
lCt = 0
End If

End If
End If
With Worksheets("Totals")
.Range("G", lTotNameRow) = l16Rct<----ERROR

gives me an "Object Defined" error at the marked line. Any ideas?
Thanks!




davegb

Object Defined error
 

Bob Phillips wrote:
Maybe try

.Range("G" & lTotNameRow) = l16Rct

or

.Cells(lTotNameRow, "G") = l16Rct

--

HTH

RP
(remove nothere from the email address if mailing direct)


"davegb" wrote in message
oups.com...
This code:

Sub CountReasonContactCode()
Dim Wksht As Worksheet
Dim rReason As Range
Dim lRow As Long
Dim lCurRow As Long
Dim rCell As Range
Dim l16Rct As Long
Dim l16Act As Long
Dim l16BGct As Long
Dim lCt As Long
Dim lTotNameRow As Long



lRow = 107
lTotNameRow = 4
l16Rct = 0
l16Act = 0
l16BGct = 0

For Each Wksht In ThisWorkbook.Worksheets


Set rReason = ActiveSheet.Range("D8", Cells(lRow, "D"))

For Each rCell In rReason
If rCell = "16" Then

lCt = InStr(1, UCase(rCell.Offset(0, 2).Value), "R")
If lCt 0 Then
l16Rct = l16Rct + 1
lCt = 0
End If

lCt = InStr(1, UCase(rCell.Offset(0, 2).Value), "A")
If lCt 0 Then
l16Act = l16Act + 1
lCt = 0
End If

lCt = InStr(1, UCase(rCell.Offset(0, 2)).Value, "B")
If lCt 0 Then
l16BGct = l16BGct + 1
Else
lCt = InStr(1, UCase(rCell.Offset(0, 2)).Value, "G")
If lCt 0 Then
l16BGct = l16BGct + 1
lCt = 0
End If

End If
End If
With Worksheets("Totals")
.Range("G", lTotNameRow) = l16Rct<----ERROR

gives me an "Object Defined" error at the marked line. Any ideas?
Thanks!


Thanks, Bob!



All times are GMT +1. The time now is 05:15 PM.

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