簡體   English   中英

根據另一個單元格的值更改單元格的值

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

我有2000行以上的工作表,單元格S中有一些值,基於單元格S我需要更改單元格V中的值

例如,如果單元格S的值<3552小於單元格V = 241,則V = 240

代碼需要檢查每一行

TNX

需要在VBA中完成

試試這個:

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