0

I am comparing the values from column A to the values in Column B and expecting an output in Column C. Column A contains IDs. Each ID can have a Cloud or Not Cloud component. An app that is all cloud should have the output of the cloud. An app that is all not cloud should have the output of the cloud. An App with cloud and not cloud components is a hybrid

I have tried a basic excel formula comparing the range of the values in column A to the values in column B but there must be an easier way in VBA. I am new to coding but I do not believe it needs to be as complex as storing the values in an Array.

Sub CompareCells()
    If Range("AA:AA").value = Range("AA:AA").value Then
       'Not sure what to do here to evaluate after making sure the range is true
    Else
        'Not sure where to go next
    End If
End Sub

Example picture attached. The output should give the value of Not cloud, Hybrid, or Cloud depending on the disposition values of each applicationenter image description here

4
  • 1
    This would actually be a lot easier with a formula.. Commented Sep 16, 2019 at 15:00
  • The list will always be sorted by the ID? Commented Sep 16, 2019 at 15:00
  • Yes it will always be sorted by the ID Commented Sep 16, 2019 at 15:05
  • @RyanColeman check my answer below. Commented Sep 16, 2019 at 15:05

2 Answers 2

1

This would work, if entered into C2 (assuming above are in A and B) and copied down:

=IF(COUNTIFS(A:A,A2,B:B,"Cloud")=0,"Not Cloud",IF(COUNTIFS(A:A,A2,B:B,"Not Cloud")=0,"Cloud","Hybrid"))

And in R1C1 style if preferred:

=IF(COUNTIFS(C[-2],RC[-2],C[-1],"Cloud")=0,"Not Cloud",IF(COUNTIFS(C[-2],RC[-2],C[-1],"Not Cloud")=0,"Cloud","Hybrid"))

So if you were looking to create some automation for this you could use something like this:

With ActiveSheet

    .Range("C2:C12").FormulaR1C1 = _
        "=IF(COUNTIFS(C[-2],RC[-2],C[-1],""Cloud"")=0,""Not Cloud"",IF(COUNTIFS(C[-2],RC[-2],C[-1],""Not Cloud"")=0,""Cloud"",""Hybrid""))"
    ActiveSheet.Calculate
    .Range("C2:C12").Value = .Range("C2:C12").Value

End With
Sign up to request clarification or add additional context in comments.

2 Comments

The formula worked perfectly in excel. Would a similar format work for VBA?
Option 2 - You could write a macro that fills 'column C' with the formula and then paste-special-values it.. Option 3 - or you could recreate the formula in VBA using WorksheetFunction.SumIfs Option 4 - or you could write your own count routine - but in all cases the formula is the quickest easiest option. If you're looking to automate it, then I'd probably look at option 2 first.
0

This formula should do the trick:

=IF(IF(COUNTIFS(A:A;A2;B:B;"Cloud")>0;1;0)+IF(COUNTIFS(A:A;A2;B:B;"Not Cloud")>0;1;0)=2;"Hybrid";IF(COUNTIFS(A:A;A2;B:B;"Cloud");"Cloud";"Not Cloud"))

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.