Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
246 views
in Technique[技术] by (71.8m points)

excel - Comparing two cell strings to print out good or bad

Below is my VBA code that I have been racking my head around. I have 4 different values to compare against to get the result I want and multiple things to compare. If anyone could help me out with this, it would be great.

Public Sub cts_04_cmac_2_check()
    'CTS04CSPRWY CMAC 2 Check
    If (Sheet1.Range("A62") = "2.3.4/42/24/B1") And (Sheet1.Range("A63") = "2.3.4/42/1/B1") Then
            Sheet1.Range("C3").Value2 = "Good"
        Else
            Sheet1.Range("C3").Value2 = "Invalid"
    End If
    'End of CTS04CSPRWY CMAC 2 Check
End Sub

In reality I would love to have or statements included:

Public Sub cts_04_cmac_2_check()
    'CTS04CSPRWY CMAC 2 Check
    If (Sheet1.Range("A62") = "2.3.4/42/24/B1" Or Sheet1.Range("A62") = "2.3.4/42/24/B2) And (Sheet1.Range("A63") = "2.3.4/42/1/B1" Or Sheet1.Range("A63") = "2.3.4/42/1/B2") Then
            Sheet1.Range("C3").Value2 = "Good"
        Else
            Sheet1.Range("C3").Value2 = "Invalid"
    End If
    'End of CTS04CSPRWY CMAC 2 Check
End Sub

This compares 2 values to an arrays index table that changes based on a selection.

One more question is: can I continue to add additional If statements after an end if? I have about 256 checks to run through with the similar code above.

It compares these 2 Formulas:

=INDEX('Collective Node Data'!A2:AQ1048576, MATCH(I3,'Collective Node Data'!A2:A230, 0),15) =INDEX('Collective Node Data'!A2:AQ1048576, MATCH(I3,'Collective Node Data'!A2:A230, 0),26) enter image description here

Based off of this value

enter image description here

to get a "Good" or "Bad" in the CMTS Check Cells C3 enter image description here

question from:https://stackoverflow.com/questions/65843557/comparing-two-cell-strings-to-print-out-good-or-bad

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

This code does basically the same as your own, just condensed as you requested:

If (
     (  Sheet1.Range("A62") = "2.3.4/42/24/B1" And Sheet1.Range("A63") = "2.3.4/42/1/B1") Or _
     (  Sheet1.Range("A62") = "2.3.4/42/24/A1" And Sheet1.Range("A63") = "2.3.4/42/1/A1") Or _
     (  Sheet1.Range("A62") = "2.3.4/42/24/C1" And Sheet1.Range("A63") = "2.3.4/42/1/C1") _
   ) Then
        Sheet1.Range("C2").Value2 = "Good"
    Else
        Sheet1.Range("C2").Value2 = "Invalid"
End If

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...