dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 1 of 1

Thread: Stuck...Need Help with loop please!

  1. #1
    Join Date
    Nov 2018
    Posts
    1

    Stuck...Need Help with loop please!

    Hello,

    I am a VB novice and am stuck on a section of a macro I'm programming to analyze eye-tracking data. Basically, I'm trying to code yes/no if there are at least 5 consecutive cells in a column with the same value (this value ranges from 1-12). The example below is coding if the cell value is 10 (I have the same script for values 1-12). I think I have my If-thens wrong because the bold section is including cells regardless if the value is 10 or not. How can I fix this so it only includes cells in column 37 that have a value of 10? In the screenshot attached, the ten consecutive "10s" in column 37 equal a "yes" and so the respective cells in column 54 should have a 1. However, the 6 immediately following this set is also coded as a 1 when it should be a "0" (I highlighted in orange). Same goes for "1" following the next set of 5s. Thanks so much!

    Code:
    If ThisObject = OngoingObject Then
    If Cells(y, 37).Value = 10 Then
    
    If Application.WorksheetFunction.And(Cells(y + 1, 37).Value = 10, Cells(y + 2, 37).Value = 10, Cells(y + 3, 37).Value = 10, Cells(y + 4, 37).Value = 10, Cells(y + 5, 37).Value = 10) Then
    If Application.WorksheetFunction.And(Cells(y + 1, 52).Value = OngoingObject, Cells(y + 2, 52).Value = OngoingObject, Cells(y + 3, 52).Value = OngoingObject, Cells(y + 4, 52).Value = OngoingObject, Cells(y + 5, 52).Value = OngoingObject) Then
                                    Cells(y, FixationCol).Value = 1
                                    If FixationStart = 0 Then
                                        FixationStart = y
                           End If
                            	ElseIf Cells(y - 1, FixationCol).Value = 1 Then
                                    If Cells(y - 1, 52).Value = OngoingObject Then
                                        Cells(y, FixationCol).Value = 1
                                        If FixationStart = 0 Then
                                            FixationStart = y
    End If
    End If
    Else: Cells(y, FixationCol).Value = 0
                                End If
                            ElseIf Cells(y - 1, FixationCol).Value = 1 Then
                                If Cells(y - 1, 52).Value = OngoingObject Then
                                    Cells(y, FixationCol).Value = 1
                                    If FixationStart = 0 Then
                                        FixationStart = y
                                    End If
                                Else: Cells(y, FixationCol).Value = 0
                                End If
                            Else: Cells(y, FixationCol).Value = 0
                            End If
    Attached Images Attached Images  
    Last edited by 2kaud; November 2nd, 2018 at 06:14 AM. Reason: Added code tags

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)