Page 1 of 1

สอบถามการเช็ตค่าว่างแล้วโชว์ Msgbox ตามเซลล์นั้นๆครับ

Posted: Wed Feb 14, 2018 11:15 am
by kampanart
ผมจะเช็คว่า Cell ไหนไม่มีค่าแล้วให้โชว์ Msgbox "ERROR + Cell name นั้นๆ" ปัจจุบันผม ใช้ if ทั้งหมด 365 วัน ครับช่วยแนะนำให้ลดปริมาณการใช้ IF หน่อยครับ


Sub check_Data()
Dim OutPut As Integer
If Sheet1.Range("B2").Value <> "OK" Then
OutPut = MsgBox("ERROR DAY1")
End If
If Sheet1.Range("C2").Value <> "OK" Then
OutPut = MsgBox("ERROR DAY2")
End If
End Sub

Re: สอบถามการเช็ตค่าว่างแล้วโชว์ Msgbox ตามเซลล์นั้นๆครับ

Posted: Wed Feb 14, 2018 12:54 pm
by puriwutpokin
kampanart wrote: Wed Feb 14, 2018 11:15 am ผมจะเช็คว่า Cell ไหนไม่มีค่าแล้วให้โชว์ Msgbox "ERROR + Cell name นั้นๆ" ปัจจุบันผม ใช้ if ทั้งหมด 365 วัน ครับช่วยแนะนำให้ลดปริมาณการใช้ IF หน่อยครับ


Sub check_Data()
Dim OutPut As Integer
If Sheet1.Range("B2").Value <> "OK" Then
OutPut = MsgBox("ERROR DAY1")
End If
If Sheet1.Range("C2").Value <> "OK" Then
OutPut = MsgBox("ERROR DAY2")
End If
End Sub
ปรับเป็น

Code: Select all

Sub check_Data()
Dim OutPut As Integer
Dim i As Integer
For i = 2 To Cells(1, Columns.Count).End(xlToLeft).Column
If Sheet1.Cells(2, i).Value <> "OK" Then
OutPut = MsgBox("ERROR DAY" & i - 1)
End If
Next i
End Sub