hi I have a problem in inputting values into a column with conditions and referring to the other 2 or more columns to determine the input of the other column using VBA. for example there are 3 columns called RAG cost (C), RAG Resources (R) and RAG Benefits (B). this 3 columns will determine the input value in a column called Overall RAG using VBA. for example if column (C) or column (B) contains the value"R" , then the overall RAG Status will be input as "A" in the respective rows. I tried using the if else statement but it doesn't seems to work. to make it clearer this is the example: if RAG Cost(C) OR RAG Resources(R) VALUES = "R" then Overall RAG status= "A".
You don't need vba for this you can write a simple formula like
=IF(ISERROR(MATCH("R",B2:D2,0)),"","A")
If You want code please try this
Sub rgb()
Dim lstrow As Long
Dim i As Long
Dim LastCol As Long
Dim j As Long
lstrow = Range("B" & Sheets("Sheet1").Rows.Count).End(xlUp).Row
LastCol = Sheets("Sheet1").Cells(1, Sheets("Sheet1").Columns.Count).End(xlToLeft).Column
For i = 2 To lstrow
For j = 2 To LastCol
If ActiveSheet.Cells(i, j).Value = "R" Then
Range("A" & i).Value = "A"
End If
Next j
Next i
End Sub
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments