changing value of cell based on value of another c

2019-08-03 16:37发布

i have sheet with 2000+ rows, in cell S i have some value, based on cell S i need to change value in cell V

for example if value of cell S is < 3552 than cell V= 241 else V=240

code need to check every row

tnx

1条回答
对你真心纯属浪费
2楼-- · 2019-08-03 17:10

need to be done in vba

Try this one:

Sub test()
    Dim lastrow As Long
    'change Sheet1 to suit
    With ThisWorkbook.Worksheets("Sheet1")
        'find lastrow in column S
        lastrow = .Cells(.Rows.Count, "S").End(xlUp).Row
        'change V1 to, say, V2 if your data starts from V2
        With Range("V1:V" & lastrow)
            'calculate result with formula
            .Formula = "=IF(S1<3552,241,240)" 'change S1 to, say, S2 if your data starts from S2
            'rewrite formula with values
            .Value = .Value
        End With
    End With
End Sub
查看更多
登录 后发表回答