我正在尝试创建一个宏来执行对范围的检查,如果单元格被格式化为红色(基于条件格式),则停止子...否则继续。
Sub O_Upload()
' Keyboard Shortcut: Ctrl+Shift+U
Dim Wb1 As Workbook, ws1 As Worksheet, ws2 As Worksheet, ws3 As Worksheet,
wbactive As Workbook, wsactive As Worksheet, lstrow As Long
Set Wb1 = Workbooks("spreadsheet.xlsx")
Set ws1 = Wb1.Sheets("Stage 1 Trim")
Set ws2 = Wb1.Sheets("Stage 2 Data Validation")
Set ws3 = Wb1.Sheets("_1010u Sheet")
Set wbactive = ActiveWorkbook
Set wsactive = wbactive.Sheets("Data")
wsactive.range("B10").Select
lstrow = Selection.End(xlDown).Row
wsactive.range("A10:V" & lstrow).Copy Destination:=ws1.range("A4")
ws1.range("X4:AS" & lstrow).Copy
ws2.range("A3").PasteSpecial xlPasteValues
'add red validation check
'if red stop
'if green copy to ws3
Dim cel As range
For Each cel In ws2.range("A3:V" & lstrow)
If cel.Interior.Color = RGB(255, 0, 0) Then
MsgBox ("Data contains errors!"), vbOKOnly
Exit Sub
End If
Next
ws2.range("A3:V" & lstrow).Copy
ws3.range("B13").PasteSpecial xlPasteValues
MsgBox "Data is ready to be uploaded", vbOKOnly
End Sub
我得到的错误是在线 - 对于每个cel在ws2.range(“A3:V”& lstrow) 我很感激帮助。
答案 0 :(得分:0)