ลบข้อมูลภายในเซลล์ที่ทำการบันทึกข้อมูลแล้ว VBA
Posted: Mon Oct 10, 2022 1:04 pm
เรียนทุกท่าน ผมอยากให้ เมื่อผมกดปุ่มบันทึกแล้ว (SAVE TO ORACLE)ให้ทำการบันทึกเข้าสู่ระบบ และลบข้อมูลที่อยู่ในexcel ภายในเซลล์ที่ผมกำหนดออกให้เหลือแต่ช่องใส่ข้อมูลเปล่าๆเหมือนเดิม(N,O,P,Q,R)ผมต้องการคำแนะนำในการทำงานของระบบที่ผมกำลังศึกษาและพัฒนาอยู่ตอนนี้ครับ ขอบคุณครับ
Code: Select all
Sub oracle_con()
Dim cn As ADODB.Connection
Dim s As String
Dim r As Long
Dim bError As Boolean
bError = False
Set cn = New ADODB.Connection
cn.ConnectionString = " "
cn.Open
Dim answer As VbMsgBoxResult
answer = MsgBox("Have you checked?", vbYesNo, "Please make sure before entering the system.")
If answer = vbYes Then
For r = 2 To 20
If Trim(Cells(r, 14)) = "" Or Trim(Cells(r, 15)) = "" Or Trim(Cells(r, 16)) = "" Or Trim(Cells(r, 17)) = "" Or Trim(Cells(r, 18)) = "" Then
'Do Notning
If Trim(Cells(r, 14)) = "" Then
Cells(r, 14).Borders.Color = vbBlack
Cells(r, 14).Interior.Color = vbRed
End If
If Trim(Cells(r, 15)) = "" Then
Cells(r, 15).Borders.Color = vbBlack
Cells(r, 15).Interior.Color = RGB(205, 205, 180)
End If
If Trim(Cells(r, 16)) = "" Then
Cells(r, 16).Borders.Color = vbBlack
Cells(r, 16).Interior.Color = vbRed
End If
If Trim(Cells(r, 17)) = "" Then
Cells(r, 17).Borders.Color = vbBlack
Cells(r, 17).Interior.Color = RGB(205, 205, 180)
End If
If Trim(Cells(r, 18)) = "" Then
Cells(r, 18).Borders.Color = vbBlack
Cells(r, 18).Interior.Color = vbRed
End If
bError = True
Else
s = "insert into column values('"
s = s & Cells(r, 14) & "','"
s = s & Cells(r, 15) & "','"
s = s & Cells(r, 16) & "','"
s = s & Cells(r, 17) & "','"
s = s & Cells(r, 18) & "',"
s = s & "SYSDATE)"
cn.Execute s
End If
Next
If bError = True Then
MsgBox ("There is information that cannot be saved.")
End If
End If
End Sub