简体   繁体   中英

I am have trouble getting my if statements and cases to run

I am trying to add information into a column with existing information. I do not want to overwrite the existing values. The goal is to use select and if statements to evaluate criteria then add the new results to the column without overwriting existing info.

The first select statement works but replacing not cloud with "null" but now I need the second select to work if the cells are empty.

I have tried several if statements and now moved to switch case so multiple conditions can be evaluated.

Dim Bucket As String
Bucket = .Cells(i, "FI").value     

Select Case Bucket
  Case "Decommissioned/Retired", "DR Enabled", NO_DR, "Vendor", "Cloud"
      .Cells(i, "FI") = .Cells(i, "FI")
  Case "Not Cloud"
      .Cells(i, "FI") = ""

  If IsEmpty(Bucket) = True Then
    Select Case DR_Ready
      Case "BDC", "SDC","BDC;#CDC","SDC ;#Externally" 
        "BDC;#CDC;#NDC;#IDC;#SDC" 
      .Cells(i, "FI") = "DR in Place (Not in Program)"
    End Select
  End If

End Select

I am looking for "DR In Program" to be placed in the empty cells that meet the condition presented in the case containing DR_Ready.

Bucket is assigned before the Select block; that local variable is holding a copy of the value of .Cells(i, "FI").value at the time of that assignment - which means .Cells(i, "FI") = "" isn't affecting its value.

If IsEmpty(Bucket) (note: = True is redundant) will always be False regardless: it's running in the "Not Cloud" case, and Bucket can never be both "Not Cloud" and Empty .

That said, "" isn't Empty ; even if assigning .Cells(i, "FI") = "" somehow affected Bucket , If IsEmpty(Bucket) would still be False . Looks like you want the body of that nested If block to be executed unconditionally inside the "Not Cloud" case - but that's mere speculation.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM