Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default Stops at certain row with Error 91

OK this one is strange.

Used range is 831 rows.

The following code runs fine until it reaches row 804. When it errors
with Object variable or With Block Variable not set.

The row above (803) has data in it just like 804.

If I use the other method to determine rows, it only reports 803 rows.

Thanks in advance!
David

Dim MyCell As String
Dim ASheet As Worksheet
Dim Counter As Long
Dim TopRow As Range
Dim BotRow As Range
Dim NumOfRows As Long
Dim EleNum As Long
Dim A As Long

Set ASheet = Worksheets("Main Data Sheet")

'Set topCel = ASheet.Range("D6")
'Set bottomCel = ASheet.Range("D65536").End(xlUp)
'Set SourceRange = ASheet.Range(topCel, bottomCel)
'NumOfRows = SourceRange.Rows.Count + 1
NumOfRows = ASheet.UsedRange.Rows.Count
AC_ID 'assign Array to AACData

For A = 6 To NumOfRows
MyCell = Range("D" & CStr(A)).Value
If Left(MyCell, 2) = "TT" Then
EleNum = TTNum_Search_2(MyCell)'Returns element# of array.
If EleNum < 0 Then
ASheet.Range("D" & CStr(A)).Comment.Text _
(AACData(EleNum)(1))
ASheet.Range("D" & _
CStr(A)).Comment.Shape.TextFrame._
Characters.Font.Size = 16
End If
End If
Next

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default Stops at certain row with Error 91

Oops, sorry.

It stops on this line or the next line.
ASheet.Range("D" & CStr(A)).Comment.Text _
(AACData(EleNum)(1))

Thanks,

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Stops at certain row with Error 91

Use code like this to see what might be going wrong

Dim cmt as Comment
Dim rng as Range
For A = 6 To NumOfRows
MyCell = Range("D" & CStr(A)).Value
If Left(MyCell, 2) = "TT" Then
EleNum = TTNum_Search_2(MyCell)'Returns element# of array.
If EleNum < 0 Then
On Error Resume Next
set rng = Nothing
set cmt = Nothing
set rng = Asheet.Range("D" & cStr(A))
if rng is nothing then
msgbox "Problem with range reference"
exit sub
end if
set cmt = rng.Comment
if cmt is nothing then
msgbox rng.Address & " doesn't have a comment"
exit sub
end if
On Error goto 0

' don't enclose AACData in parens

ASheet.Range("D" & CStr(A)).Comment.Text _
AACData(EleNum)(1)
ASheet.Range("D" & _
CStr(A)).Comment.Shape.TextFrame._
Characters.Font.Size = 16
End If
End If
Next

--
Regards,
Tom Ogilvy


"David Sisson" wrote in message
oups.com...
Oops, sorry.

It stops on this line or the next line.
ASheet.Range("D" & CStr(A)).Comment.Text _
(AACData(EleNum)(1))

Thanks,



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default Stops at certain row with Error 91

ARGGGHH!

I failed to mention that this was the first time these cells had
Comments added. Or so I thought.

I assumed (that always gets ya!) that Comment.Text String would SET a
Comment if not there. Nope, ya gotta use the AddComment!

After some rereading in help file, I realized my mistake.

So here's the working code segment.

Thanks, Tom!

Set Cmt = Rng.Comment

If Cmt Is Nothing Then
ASheet.Range("D" & CStr(A)).AddComment.Text
AACData(EleNum)(1)
ASheet.Range("D" &
CStr(A)).Comment.Shape.TextFrame.Characters.Font.S ize = 16

Else

ASheet.Range("D" & CStr(A)).Comment.Text AACData(EleNum)(1)
ASheet.Range("D" &
CStr(A)).Comment.Shape.TextFrame.Characters.Font.S ize = 16
End If

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
After sharing workbook VB code stops working. Runtime Error 1004 Patrick LaFerriere Excel Programming 0 October 5th 05 04:01 PM
Tab Stops brentm Excel Programming 2 April 21st 05 07:20 PM
overflow error 6.. the macro just stops any idea why? ste mac Excel Programming 4 February 7th 05 04:00 PM
Tab stops TO Excel Programming 5 October 23rd 04 06:31 PM
Tab Stops Summer Excel Programming 1 April 29th 04 05:37 PM


All times are GMT +1. The time now is 01:21 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"