This code working perfectly which is written below:
Private Sub CommandButton1_Click()
Dim con As Object
Dim cellsdata As Range
Dim cl As Range
Dim str As String
Dim ins As String
Dim insqry As String
Dim flag As Integer
Dim cnt_for_space As Integer
Dim qryary(200) As String
Dim i As Integer
Dim qryindex As Integer
Dim cnt As Integer
Set cellsdata = Worksheets(1).Range("A2:N100")
Set con = CreateObject("ADODB.Connection")
con.ConnectionString = "DRIVER=SQL Server;SERVER=PANKAJ;UID=ADMIN;WSID=USER;DATABASE=hotel;Trusted_Connection=Yes"
i = 1
qryindex = 0
cnt_for_space = 0
flag = 0
str = "UPDATE call_dtl set"
insqry = "insert into call_dtl(call_no,cust_name,ven,cont_name,cont_no,rep_no,prob_report,cse,call_rec,call_arr,call_comp,status,remks)values('"
For Each cl In cellsdata
If (i = 1) Then
If (cl.Value = "") Then
cnt_for_space = cnt_for_space + 1
End If
str = str & " call_no='" & cl.Value & "'"
insqry = insqry & cl.Value & "','"
End If
If (i = 2) Then
If (cl.Value = "") Then
cnt_for_space = cnt_for_space + 1
End If
str = str & ",cust_name='" & cl.Value & "'"
insqry = insqry & cl.Value & "','"
End If
If (i = 3) Then
If (cl.Value = "") Then
cnt_for_space = cnt_for_space + 1
End If
str = str & ",ven='" & cl.Value & "'"
insqry = insqry & cl.Value & "','"
End If
If (i = 4) Then
If (cl.Value = "") Then
cnt_for_space = cnt_for_space + 1
End If
str = str & ",cont_name='" & cl.Value & "'"
insqry = insqry & cl.Value & "','"
End If
If (i = 5) Then
If (cl.Value = "") Then
cnt_for_space = cnt_for_space + 1
End If
str = str & ",cont_no='" & cl.Value & "'"
insqry = insqry & cl.Value & "','"
End If
If (i = 6) Then
If (cl.Value = "") Then
cnt_for_space = cnt_for_space + 1
End If
str = str & ",rep_no='" & cl.Value & "'"
insqry = insqry & cl.Value & "','"
End If
If (i = 7) Then
If (cl.Value = "") Then
cnt_for_space = cnt_for_space + 1
End If
str = str & ",prob_report='" & cl.Value & "'"
insqry = insqry & cl.Value & "','"
End If
If (i = 8) Then
If (cl.Value = "") Then
cnt_for_space = cnt_for_space + 1
End If
str = str & ",cse='" & cl.Value & "'"
insqry = insqry & cl.Value & "','"
End If
If (i = 9) Then
If (cl.Value = "") Then
cnt_for_space = cnt_for_space + 1
End If
str = str & ",call_rec='" & cl.Value & "'"
insqry = insqry & cl.Value & "','"
End If
If (i = 10) Then
If (cl.Value = "") Then
cnt_for_space = cnt_for_space + 1
End If
str = str & ",call_arr='" & cl.Value & "'"
insqry = insqry & cl.Value & "','"
End If
If (i = 11) Then
If (cl.Value = "") Then
cnt_for_space = cnt_for_space + 1
End If
str = str & ",call_comp='" & cl.Value & "'"
insqry = insqry & cl.Value & "','"
End If
If (i = 12) Then
If (cl.Value = "") Then
cnt_for_space = cnt_for_space + 1
End If
str = str & ",status='" & cl.Value & "'"
insqry = insqry & cl.Value & "','"
End If
If (i = 13) Then
If (cl.Value = "") Then
cnt_for_space = cnt_for_space + 1
End If
str = str & ",remks='" & cl.Value & "'"
insqry = insqry & cl.Value & "')"
End If
If (i = 14) Then
If (cl.Value = "") Then
cnt_for_space = cnt_for_space + 1
flag = 1
End If
str = str & " where itm_id=" & cl.Value & ""
End If
If i = 14 Then
i = 0
If cnt_for_space = 14 Then
Exit For
End If
If (flag = 0) Then
qryary(qryindex) = str
Else
qryary(qryindex) = insqry
End If
cnt_for_space = 0
flag = 0
qryindex = qryindex + 1
str = "UPDATE call_dtl set"
insqry = "insert into call_dtl(call_no,cust_name,ven,cont_name,cont_no,rep_no,prob_report,cse,call_rec,call_arr,call_comp,status,remks)values('"
End If
i = i + 1
Next cl
For lp = 0 To qryindex - 1
con.Open
con.Execute qryary(lp)
oldValue = Application.ActiveCell.Value
con.Close
Next lp
MsgBox "Data Updated Successfully"
ThisWorkbook.RefreshAll
End Sub