Use Left, or , and together in VBA Macro



I have to check  in Column A whether any number starts with 113 or 114 and the corresponding value for that cell in Column B is positive or negative and if it is negative, then in Column C against that cell enter value as A. Otherwise Column C should be blank.

I wrote the macro given below, but it is not working.

Sub Example()
Dim c As Range
For Each c In Range("a1:a5")
For Each d In Range("b1:b5")
For Each e In Range("c1:c5")
If c.Value = "" Then
e.Value = ""
If ((Left(c.Value, 3) = 113 Or Left(c.Value, 3) = 114)) And sgn (d.Value) = -1 Then
e.Value = "A"
End If
End If
End Sub

Can anybody help please.

Thanks in advance……

Top Contributor Asked on March 20, 2017 in VBA: Macros.
Add Comment
1 Answer(s)
Best answer

Hi, Here is the updated VBA Macro fro your requirement:


In this macro, we are looping through from 1 to 5. And Checking if A1 is starts with 113 or 114, if B1 is a negative value.

If this meets the condition we are printing letter “A” in C1 other wise Blank.

The loop will continue check the A2,A3..up to A5.

Sub VBAF1_CheckCellsIfMeetsConditions()
Dim c As Range
'Loop through From Row 1 to 5
For iCntr = 1 To 5
'Check if its meeting the criterian
If (Left(Range("A" & iCntr), 3) = 113 Or Left(Range("A" & iCntr), 3) = 114) And Range("B" & iCntr) < 0 Then
Range("C" & iCntr) = "A" 'Enter A if meets
Range("C" & iCntr) = "" 'Other wise Blank
End If
End Sub


Keymaster Answered on March 20, 2017.

Thanks for the detailed and informative answer………

on March 20, 2017.
Add Comment
  • Found this useful?

    Please share using the share button above.

    If you found the answer is best answer for your question, Please mark as 'best answer' by clicking on the right tick mark icon at the left side of the answer.

    Found the answer useful and wants to credit the user, then vote the answer (vote up).

  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.