mardi 26 février 2019

Loop, if statements and column affecting another - VBA

Good Afternoon,

I am trying to automatize a report I have to build on a weekly basis, and I am struggling on one of the actions. Basically, I would like to check the content of column AN. Following the content, it should write in column BD a specific information. I would like the range to be from AN2 to last row. (there is no blank).

'To initiate the loop:
Sub New_Customer_Performance()


Dim LastRow As Long, x As Long LastRow = Cells(Rows.Count, "AN").End(xlUp).Row For x = 1 To LastRow
  Range("BC2").Select




'Then the IF statements: If Cells(x, "AN").Value Like "Time" Then Cells(x, "BD").Value = "A_On Time" ElseIf Cells(x, "AN").Value Like "*Credit*" Then Cells(i, "BD").Value = "B_Credit hold" ElseIf Cells(x, "AN").Value Like "*Customer*" Then Cells(i, "BD").Value = "C_Customer setup" End If Next x End Sub

basically, there is 8 or 9 Else If statements, but they are all written the same way. I might add a "Else" at the end in case there is other scenario. Thank you in advance for your help !

Aucun commentaire:

Enregistrer un commentaire