简体   繁体   English

VBA比较列和消防宏

[英]VBA to compare columns and fire macro

Hi I have three columns (ABC) with multiple rows. 嗨,我有三列(ABC)多行。

I need to check if B is greater than C, and if so to add 1 to C and repeat until the last row. 我需要检查B是否大于C,如果是,则将C加1并重复直到最后一行。 I'm getting a syntax error, any help much apprecicated! 我遇到语法错误,不胜感激!

Sub test6()

Dim LastRow As Long, i As Long
LastRow = Cells(Rows.Count, "A").End(xlUp).Row
For i = 1 To LastRow
If Range("B" & i).Value > ("C" & i).Value Then Range("C" & i).Value 1


Else: End If

Next i
End Sub

删除Else: End If如Scott Craner在评论中所述,并更改If语句:

If Range("B" & i).Value > Range("C" & i).Value Then Range("C" & i).Value = Range("C" & i).Value + 1

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

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