Consulting

Results 1 to 3 of 3

Thread: Solved: Read cell comment text into array varible

  1. #1
    VBAX Regular
    Joined
    Sep 2006
    Posts
    8
    Location

    Solved: Read cell comment text into array varible

    I'm trying the read the text in a comment to an element of a udt array.

    UDT ....Summary().discription as string

    [vba]For j = 1 To UBound(DefectCode())
    ReDim Preserve DefectCodeSummary(1 To j)
    DefectCodeSummary(j).Discription = Worksheets("Lists").Range(Cells(j + 1, _
    6).Address(xlA1)).Comment.Text
    Next j[/vba]

    i get an application or object defined error when this runs. it works if i specify a single cell rather than looping through. (cells(2,6) works, but cells(i+1,6) does not, even though they refer to the same cell at the first loop)

  2. #2
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Try
    [VBA]
    DefectCodeSummary(j) = Worksheets("Lists").Cells(j + 1, 6).Comment.Text

    [/VBA]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  3. #3
    VBAX Regular
    Joined
    Sep 2006
    Posts
    8
    Location
    Quote Originally Posted by mdmackillop
    Try
    [vba]
    DefectCodeSummary(j) = Worksheets("Lists").Cells(j + 1, 6).Comment.Text

    [/vba]
    changed to:
    [vba] DefectCodeSummary(j).discription = Worksheets("Lists").Cells(j + 1, 6).Comment.Text[/vba]
    because of the udt array (i have string and integer data types i want to keep together)

    Stupid me, my j + 1 was making the counter go past the end of the array. For some reason, my control array has a blank at position 1, so on similar things i had used [vba]for j =2 to ubound(array())[/vba] but on this one i was using 1 to ubound, then adding 1 to get the right data. I missed the error because i was worried that i ddint have the syntax right for the comments.text code

    Thanks for your help.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •