Home > Software design >  Excel VBA If range.value = something then fills Columns G
Excel VBA If range.value = something then fills Columns G

Time:01-23

For example

if range A14:A200

if A14 = 1 so fill G14 Ok if A14 = 1 so fill G14 Ok and so on

For example if range A14:A200 if A14 = 1 so fill G14 Ok if A15 = 1 so fill G15 Ok and so on

CodePudding user response:

you could use the excel formulas:

Sub IFSomething()

    With Range("A14:A200") reference the needed range
        With .Offset(, 6) ' reference the cells 6 columns to the right of referenced range
            .FormulaR1C1 = "=IF(RC[-6]=1,""OK"","""")" ' place a formula in referenced range
            .Value = .Value ' leave only values
        End With
    End With
    
End Sub

CodePudding user response:

So here is revise solution I hope this resolve your query.

Sub If_loop_test()

Dim x As Integer
    
For x = 1 To 200
  
    If Range("A" & x).Value = 1 Then
    Range("G" & x).Value = "ok"
    End If
Next
    
End Sub

CodePudding user response:

The code should be like below:

Sub If_Test()

If Range("A1").Value = 1 Then Range("G1").Value = "ok"

End Sub

  • Related