ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Data Modification (https://www.excelbanter.com/excel-programming/358973-data-modification.html)

Syed Haider Ali[_34_]

Data Modification
 

Hi Dears

I have following codes to Enter New data into Sheet.

Private Sub CommandButton1_Click()
Dim irow As Long
Dim ws As Worksheet
Dim rng As Range
Dim res As Variant

Set ws = Worksheets("CIssue")

With ws
Set rng = .Range(.Range("a2"), .Range("a2").End(xlDown))
End With

res = Application.Match(CLng(CDate(Me.TextBox1.Value)), rng, 0)

If IsError(res) Then

irow = ws.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row

ws.Cells(irow, 1).Value = Me.TextBox1.Value
ws.Cells(irow, 2).Value = Me.TextBox2.Value
ws.Cells(irow, 3).Value = Me.TextBox3.Value
Me.TextBox1 = ""
Me.TextBox2 = ""
Me.TextBox3 = ""
Me.TextBox1.SetFocus
Else
MsgBox "Data Already Exist", vbCritical
TextBox2 = Sheet8.Range("a1").Offset(res, 1).Value
TextBox3 = Sheet8.Range("a1").Offset(res, 2).Value
End If
Me.TextBox1.SetFocus

End Sub

I would like to ask the codes for modification of data. Suppose when i
put the required code in textbox1.

1. It search the data
2. if found then retrive the data in Textbox2 and textbox3
3. Put the replaced data in the existing row.

Thanks,

Syed Haider Ali


--
Syed Haider Ali
------------------------------------------------------------------------
Syed Haider Ali's Profile: http://www.excelforum.com/member.php...o&userid=21994
View this thread: http://www.excelforum.com/showthread...hreadid=533191


Tom Ogilvy

Data Modification
 
Private Sub CommandButton1_Click()
Dim irow As Long
Dim ws As Worksheet
Dim rng As Range
Dim res As Variant

Set ws = Worksheets("CIssue")

With ws
Set rng = .Range(.Range("a2"), .Range("a2").End(xlDown))
End With

res = Application.Match(CLng(CDate(Me.TextBox1.Value)), rng, 0)

If IsError(res) Then

irow = ws.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row

ws.Cells(irow, 1).Value = Me.TextBox1.Value
ws.Cells(irow, 2).Value = Me.TextBox2.Value
ws.Cells(irow, 3).Value = Me.TextBox3.Value
Me.TextBox1 = ""
Me.TextBox2 = ""
Me.TextBox3 = ""
Me.TextBox1.SetFocus
Else
ans = MsgBox( "Data Already Exist, Update?", vbCritical+vbYesNo)
if ans = vbYes then
set rng1 = rng(res)
rng1.offset(0,1).Value = TextBox2
rng1.offset(0,2).Value = Textbox3
End If
End If
Me.TextBox1.SetFocus

End Sub

I would like to ask the codes for modification of data. Suppose when i
put the required code in textbox1.


--
Regards,
Tom Ogilvy


"Syed Haider Ali"
<Syed.Haider.Ali.26bnqm_1145131801.7331@excelfor um-nospam.com wrote in
message news:Syed.Haider.Ali.26bnqm_1145131801.7331@excelf orum-nospam.com...

Hi Dears

I have following codes to Enter New data into Sheet.

Private Sub CommandButton1_Click()
Dim irow As Long
Dim ws As Worksheet
Dim rng As Range
Dim res As Variant

Set ws = Worksheets("CIssue")

With ws
Set rng = .Range(.Range("a2"), .Range("a2").End(xlDown))
End With

res = Application.Match(CLng(CDate(Me.TextBox1.Value)), rng, 0)

If IsError(res) Then

irow = ws.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row

ws.Cells(irow, 1).Value = Me.TextBox1.Value
ws.Cells(irow, 2).Value = Me.TextBox2.Value
ws.Cells(irow, 3).Value = Me.TextBox3.Value
Me.TextBox1 = ""
Me.TextBox2 = ""
Me.TextBox3 = ""
Me.TextBox1.SetFocus
Else
MsgBox "Data Already Exist", vbCritical
TextBox2 = Sheet8.Range("a1").Offset(res, 1).Value
TextBox3 = Sheet8.Range("a1").Offset(res, 2).Value
End If
Me.TextBox1.SetFocus

End Sub

I would like to ask the codes for modification of data. Suppose when i
put the required code in textbox1.

1. It search the data
2. if found then retrive the data in Textbox2 and textbox3
3. Put the replaced data in the existing row.

Thanks,

Syed Haider Ali


--
Syed Haider Ali
------------------------------------------------------------------------
Syed Haider Ali's Profile:

http://www.excelforum.com/member.php...o&userid=21994
View this thread: http://www.excelforum.com/showthread...hreadid=533191





All times are GMT +1. The time now is 12:24 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com