Hi,
I am new to macros and trying to upload data using macro row by row. Now say one of the rows has an issue with data and my macro code threw error, i want to handle this error in the following manner. I want to highlight this row with some colour. Also i want my code to start processing the next row of the sheet. Can this be done? Please help.
For example take i have total of 100 data rows in a sheet which i want to upload to the database. Say 23rd row had data problem and my marco code threw error. I want this 23rd row to be highlighted in a different colour. and i want my code to continue from next row. how can i achieve it?
below is my macro code.
Global Const dsn_str = "ODBC;DSN=FBCJDS;UID=FCUBSLIVE;PWD=FBCJDS;"
Sub Upload()
' NDB Bank BIC Upload ...
'
' Keyboard Shortcut: Ctrl+Shift+U
'
Dim chan As Integer
Dim sqlstr As String
Dim delstr As String
Dim mast_sql As String
Dim del_sql As String
Dim rowcnt As Integer
Dim curcell As String
Dim mysheet As String
Dim ll As Integer
Dim tbname As String
Dim objSession As Object
Dim objDataBase As Object
'On Error GoTo bomb
Set objSession = CreateObject("OracleInProcServer.XOraSession")
Set objDataBase = objSession.OpenDatabase("FBCJDS", "FCUBSLIVE/FBCJDS", 0&)
BeginTrans
mysheet = Application.InputBox("Sheet To upload", "", ActiveSheet.Name)
Sheets(mysheet).Activate
Range("A1").Select
tbname = LTrim(RTrim(UCase(Range("A1").Value)))
mast_sql = "Insert into " + ActiveCell + " ("
del_sql = "Delete " + ActiveCell + " Where "
Range("A2").Select
del_sql = del_sql + ActiveCell + " = "
While ActiveCell <> "~~END~~"
mast_sql = mast_sql + ActiveCell + ","
ActiveCell.Next.Activate
Wend
mast_sql = Mid(mast_sql, 1, Len(mast_sql) - 1) + ")" + " values ("
rowcnt = 3
curcell = "A" + Trim(Str(rowcnt))
Range(curcell).Select
While ActiveCell <> "~~END~~"
sqlstr = mast_sql
delstr = del_sql & "'" & ActiveCell & "'"
MsgBox delstr, 48
While ActiveCell <> "~~END~~"
If ActiveCell = "" Then
sqlstr = sqlstr + "NULL ,"
ElseIf IsNumeric(ActiveCell) Then
sqlstr = sqlstr & Chr(39) & ActiveCell & Chr(39) & ","
ElseIf IsDate(ActiveCell) Then
sqlstr = sqlstr + Chr(39) + UCase(Format(ActiveCell, "dd-mmm-yy")) + Chr(39) + ","
Else
sqlstr = sqlstr + Chr(39) + Trim(ActiveCell) + Chr(39) + ","
End If
ActiveCell.Next.Activate
Wend
sqlstr = Mid(sqlstr, 1, Len(sqlstr) - 1) + ")"
objDataBase.ExecuteSQL (sqlstr)
rowcnt = rowcnt + 1
curcell = "A" + Trim(Str(rowcnt))
Range(curcell).Select
On Error GoTo handler 'Madhu Changes
MsgBox sqlstr, 48
Wend
CommitTrans
objDataBase.Close
Exit Sub
bomb:
If MsgBox(Error$(), 21, "ODBC") = 4 Then
Resume 0
End If
handler: 'Madhu Changes
MsgBox Err.Description 'Madhu Changes
End Sub
Regards
Puru
Bookmarks