简体   繁体   中英

VBA to compare columns and fire macro

Hi I have three columns (ABC) with multiple rows.

I need to check if B is greater than C, and if so to add 1 to C and repeat until the last row. 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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