akotu12
Thành viên mới

- Tham gia
- 22/5/18
- Bài viết
- 15
- Được thích
- 1
Em muốn chạy for các giá trị gán vào cột A1. Khi không lỗi tự động bôi xanh còn khi lỗi tự động bôi đỏ ô "A"&i đó đó thi làm ntn ạ?
code của em:
Sub conf()
Dim a As String
Dim i As Long
a = Sheet1.Range("A1000").End(xlUp).Row
For i = 3 To a
On Error GoTo X
session.findById("wnd[0]").maximize
session.findById("wnd[0]/tbar[0]/okcd").Text = "/n co11"
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/usr/ctxtCORUF-AUFNR").Text = Sheet1.Range("A" & i).Value
session.findById("wnd[0]/usr/ctxtCORUF-AUFNR").SetFocus
session.findById("wnd[0]/usr/ctxtCORUF-AUFNR").caretPosition = 7
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]").sendVKey 11
Range("A" & i).Select
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 5296274
.TintAndShade = 0
.PatternTintAndShade = 0
End With
X:
Range("A" & i).Select
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 255
.TintAndShade = 0
.PatternTintAndShade = 0
End With
Next
End Sub
code của em:
Sub conf()
Dim a As String
Dim i As Long
a = Sheet1.Range("A1000").End(xlUp).Row
For i = 3 To a
On Error GoTo X
session.findById("wnd[0]").maximize
session.findById("wnd[0]/tbar[0]/okcd").Text = "/n co11"
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/usr/ctxtCORUF-AUFNR").Text = Sheet1.Range("A" & i).Value
session.findById("wnd[0]/usr/ctxtCORUF-AUFNR").SetFocus
session.findById("wnd[0]/usr/ctxtCORUF-AUFNR").caretPosition = 7
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]").sendVKey 11
Range("A" & i).Select
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 5296274
.TintAndShade = 0
.PatternTintAndShade = 0
End With
X:
Range("A" & i).Select
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 255
.TintAndShade = 0
.PatternTintAndShade = 0
End With
Next
End Sub