简体   繁体   English

根据另一个单元格的值更改单元格的值

[英]changing value of cell based on value of another cell

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 我有2000行以上的工作表,单元格S中有一些值,基于单元格S我需要更改单元格V中的值

for example if value of cell S is < 3552 than cell V= 241 else V=240 例如,如果单元格S的值<3552小于单元格V = 241,则V = 240

code need to check every row 代码需要检查每一行

tnx TNX

need to be done in vba 需要在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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM