Changing code to mark requirement "+" for pass and "-" for fail under each scenario that was run and leave it blank otherwise

Nlhicks

Board Regular
Joined
Jan 8, 2021
Messages
244
Office Version
  1. 365
Platform
  1. Windows
Option Explicit

Sub Test2()
If ActiveSheet.Name <> "Sheet4" Then
MsgBox "Run this from the Sheet 4.", 64, "Note:"
Exit Sub
End If

Application.ScreenUpdating = False

Dim cellEstelle As Range, strEstelle$, strPassFail$
Dim varFindRequirement As Variant, lngFindRequirement&, lngNextCol&, xCol&
Dim cellEasy As Range, strEasy$
Dim varFindScenario As Variant, lngFindScenario&, lngNextRow&, xRow&

With Sheets("Sheet3")

For Each cellEstelle In Columns(1).SpecialCells(2)
Set varFindRequirement = Nothing
strEstelle = cellEstelle.Value
Set varFindRequirement = .Columns(8).Find(What:=strEstelle, LookIn:=xlFormulas, LookAt:=xlWhole)

For Each cellEasy In Columns(3).SpecialCells(2)
Set varFindScenario = Nothing
strEasy = cellEasy.Value
Set varFindScenario = .Rows(5).Find(What:=cellEasy, LookIn:=xlFormulas, LookAt:=xlWhole)


If Not varFindRequirement Is Nothing Then
lngFindRequirement = varFindRequirement.Row
If Not varFindScenario Is Nothing Then
lngFindScenario = varFindScenario.Column
'Modify thse column number boundaries as needed.
If lngFindRequirement >= 6 And lngFindRequirement <= 19 Then
If lngFindScenario >= 9 And lngFindScenario <= 16 Then

If varFindScenario.Column And cells(cellEstelle.Row, 2).Value = "Pass" Then
strPassFail = "+"
Else
strPassFail = "-"
End If

For lngFindScenario = 9 To 16
If Len(.cells(lngFindRequirement, lngFindScenario).Value) = 0 And .cells(lngFindRequirement, lngFindScenario).Interior.ColorIndex = -4142 Then .cells(lngFindRequirement, lngFindScenario).Value = strPassFail
Next lngFindScenario
End If
End If
End If
End If

Next cellEasy

Next cellEstelle

End With

Set varFindRequirement = Nothing
Application.ScreenUpdating = True
MsgBox "Completed.", , "Done."

End Sub


This is what the code above is giving me:

Test Tracking Test2 adding new section.xlsm
HIJKLMNOP
5Abort_12Cold_Cut_2Hot_Cut_1Hot_Cut_3Omega_1Pharos_1Hot_Cut_2Cold_Cut_1
6D_ANT_SFTY_01++++
7D_ANT_SFTY_02
8D_ANT_SFTY_03--
9BITO_1010
10BITO_1011++++++
11BITO_1012++++
12BITO_1013
13QNTI_01-
14QNTI_02++++
15QNTI_03
16PLT_555++++
17PLT_556++++
18PLT_557
Sheet3


From this data:
Test Tracking Test2 adding new section.xlsm
ABC
1SPS#ResultScenarios
2D_ANT_SFTY_01PassAbort_12
3D_ANT_SFTY_03FailHot_Cut_3
4BITO_1011PassPharos_1
5BITO_1012PassCold_Cut_1
6QNTI_01FailHot_Cut_1
7QNTI_02Pass
8PLT_555Pass
9PLT_556Pass
Sheet4
Cells with Conditional Formatting
CellConditionCell FormatStop If True
C2:C5Cell ValueduplicatestextNO
C8Cell ValueduplicatestextNO
 
This is what the result should be if the information above is given:

1631543632280.png

SQL:
 

Attachments

  • 1631543312426.png
    1631543312426.png
    23.3 KB · Views: 2
Upvote 0

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
I added what the data should present above. Hopefully this helps
 
Upvote 0
I did want to mention that both the scenario code and the requirement code work doing what they were designed to do. I want to combine them so that it is still requirements based however it takes the scenario into consideration if that makes sense.
 
Upvote 0
try this:
VBA Code:
Option Explicit

Sub Test2()
Dim sh4 As Worksheet, sh3 As Worksheet
Dim cc As Range
Application.ScreenUpdating = False

Dim cellEstelle As Range, strEstelle$, strPassFail$, stResult As String
Dim varFindRequirement As Variant, lngFindRequirement&, lngNextCol&, xCol&
Dim cellEasy As Range, strEasy$
Dim varFindScenario As Variant, lngFindScenario&, lngNextRow&, xRow&

Set sh3 = ThisWorkbook.Worksheets("Sheet3")
Set sh4 = ThisWorkbook.Worksheets("Sheet4")

    For Each cellEstelle In sh4.Columns(1).SpecialCells(2)
        Set varFindRequirement = Nothing
        strEstelle = Trim(cellEstelle.Value)
        strPassFail = Trim(cellEstelle.Offset(, 1).Value)
        
        Set varFindRequirement = sh3.Columns(8).Find(What:=strEstelle, LookIn:=xlFormulas, LookAt:=xlWhole)
        If varFindRequirement Is Nothing Then GoTo skipA
        lngFindRequirement = varFindRequirement.Row
        
        For Each cellEasy In sh4.Columns(3).SpecialCells(2)
            Set varFindScenario = Nothing
            strEasy = cellEasy.Value
            Set varFindScenario = sh3.Rows(5).Find(What:=Trim(strEasy), LookIn:=xlFormulas, LookAt:=xlWhole)
            
            If varFindScenario Is Nothing Then GoTo skipB
            If Not varFindScenario Is Nothing Then
                lngFindScenario = varFindScenario.Column
                'Modify thse column number boundaries as needed.
                If lngFindRequirement >= 6 And lngFindRequirement <= 19 Then
                    If lngFindScenario >= 9 And lngFindScenario <= 16 Then
                    
                        If varFindScenario.Column And strPassFail = "Pass" Then
                            stResult = "+"
                        Else
                            stResult = "-"
                        End If
                        
                        Set cc = sh3.Cells(lngFindRequirement, lngFindScenario)
                        cc.Select
                        If Len(cc.Value) = 0 And cc.Interior.ColorIndex = -4142 Then cc.Value = stResult
                    End If
                End If
            End If
skipB:
        Next cellEasy
skipA:
    Next cellEstelle

Set varFindRequirement = Nothing
Set varFindScenario = Nothing
Set sh3 = Nothing
Set sh4 = Nothing
Set cc = Nothing
Set cellEasy = Nothing
Set cellEstelle = Nothing
    
Application.ScreenUpdating = True
MsgBox "Completed.", , "Done."

End Sub
 
Upvote 0
I am getting a run-time error '1004' saying select method of Range class failed at the cc.Select
 
Upvote 0
That's because you have sheet4 as the active sheet
add sh3.select
Rich (BB code):
                        If varFindScenario.Column And strPassFail = "Pass" Then
                            stResult = "+"
                        Else
                            stResult = "-"
                        End If
                        
                        sh3.Select
                        
                        Set cc = sh3.Cells(lngFindRequirement, lngFindScenario)
                        cc.Select
                        If Len(cc.Value) = 0 And cc.Interior.ColorIndex = -4142 Then cc.Value = stResult
                    End If
                End If
 
Last edited:
Upvote 0
BTW, the code in post 16 doesn't care which is the active sheet. You may start it from any sheet.
Just remove the line cc.Select.
 
Upvote 0

Forum statistics

Threads
1,215,734
Messages
6,126,542
Members
449,316
Latest member
sravya

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top