Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7814121
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T05:05:45+00:00 2026-06-02T05:05:45+00:00

I am getting errors while looping through a dictionary trying to go to specified

  • 0

I am getting errors while looping through a dictionary trying to go to specified cells as the dictionary contains column addresses. Here is a little backround-

  1. Loop through any cells that have a comment (top row only!!)
  2. Store that column and comment text in a dictionary object
  3. Loop through the remaining rows and ONLY go to the cells in the same column as the comment from the first row. This information will then be sent to another worksheet

E.g.,

|CELL1|CELL2 (W COMMENT)|CELL3|

–Store Cell2 column address which would be 2 and the comment, select the next cell down at column position 2.

I have posted my whole class but the part you need to pay attention to is at the very bottom with the commented code. I realize it is probably a bit hefty for code so if you see some shortcuts please advise!

Option Explicit
Public buildWs As Worksheet
Public targWs As Worksheet
Public CommentVal As Comment
Public FirstRow As Range
Public targLastrow As Range
Public firstRecordRow As Range
Public commRange As Range
Public commCell As Range
Public recordRow As Range
Public LastRow As Long
Public vertRange As Range
Public vertCell As Range

'//---------------------------------------
'//getter and setter methods of the class
Public Property Get ItemNum() As Comment
    ItemNum = CommentVal
End Property
Public Property Let ItemNum(Value As Comment)
    CommentVal = ItemNum
End Property

Public Property Get Start() As Range
    Start = FirstRow
End Property
Public Property Let Start(Value As Range)
    Set FirstRow = Value
End Property

Public Property Get affBuild() As Worksheet
    affBuild = buildWs
End Property
Public Property Let affBuild(Value As Worksheet)
    Set buildWs = Value
End Property

Public Property Get allinaBuid() As Worksheet
    allinaBuild = targWs
End Property
Public Property Let allinaBuild(Value As Worksheet)
    Set targWs = allinaBuild
End Property

Public Sub setId()
    Dim rowCount As Integer
    Dim element As Variant
    Dim n As Integer
    Dim z As Integer
    Dim keyValue As New Dictionary
    Dim col As String

    On Error Resume Next
    Set commRange = buildWs.Cells _
      .SpecialCells(xlCellTypeComments)
    On Error GoTo 0
    If commRange Is Nothing Then
        MsgBox "No Comments Found"
        Exit Sub
    End If
    buildWs.Activate
    For Each commCell In commRange
        commCell.Select
        '// do something here with the cell since it meets our criteria of having a comment
        keyValue.Add ActiveCell.Column, ActiveCell.Comment.Text
    Next commCell
    '// loop through the vertical range for the 1st column to get a count of rows
    '//--------------------------------------------------------------------------
    Set vertRange = Range("A:A")
    vertRange.Select
    For Each vertCell In vertRange
        If ActiveCell.Value = "" Then
            Exit For
        Else
            rowCount = rowCount + 1
            ActiveCell.Offset(1, 0).Select
        End If
    Next vertCell
    '// row count is off by one since we don't care about the first row
    rowCount = rowCount - 1

    '// select the first real row we care about as row1 is only header info
    FirstRow.Select
    For Each element In keyValue
        col = element
        MsgBox col '<-- this displays the correct dictionary information -->
        Cells("2", col).Select '<-- this fails and gives me an error! -->
    Next element
End Sub
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T05:05:47+00:00Added an answer on June 2, 2026 at 5:05 am

    The error occurs because you need to pass integer numbers to Cells("2", col), not strings. You should either pass a Variant containing a Long or a Long.

    Dim col As Variant
    

    or

    Dim col As Long
    

    Then

    Cells(2, col).Select
    

    You also have an error here

    Public Property Let allinaBuild(Value As Worksheet)
        Set targWs = Value ' <== was   Set targWs = allinaBuild
    End Property
    

    (I replaced allinaBuild by Value)

    Same error in Let ItemNum

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I keep getting this error while trying to modify some tables. Here's my code:
While validating my CSS on http://jigsaw.w3.org/css-validator/ I am getting following errors: 1.Property zoom doesn't
I´m getting this error while trying to commit to a svn repository: svn: MKACTIVITY
I am getting an error while trying to run CFmx code on a remote
I'm getting an error while trying to use the action_mailer_tls plugin to communicate with
I'm getting follwing error while I'm trying to filter data for the second time
While looping through records in one list, I want to find a corresponding line
I'm getting an error while looping over an element children: $placeById=simplexml_load_file(http://www.43places.com/service/get_place_by_id?api_key=1234&id=.$placeId); $children=$placeById->children; echo '<ul>';
getting error while try to start service
Getting error while inserting values into database (SQL Server 2008) Implicit conversion from data

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.