Insert Record

  • Thread starter Thread starter Sohail khan
  • Start date Start date
S

Sohail khan

Sir i want to insert record one sheet cells into another sheets cells through
command button. after saving data second data will save on next row
 
Try this with Command Button on Sheet1:

Private Sub CommandButton1_Click()
Dim LRow As Long
Dim MyCell As String

LRow = Sheet2.Cells(Rows.Count, "A").End(xlUp).Row
If IsEmpty(Sheet2.Cells(LRow, 1)) Then
LRow = LRow
Else
LRow = LRow + 1
End If
MyCell = ActiveCell.Address
Sheet2.Cells(LRow, 1).Value = ActiveCell.Value
Sheet1.Range(MyCell).Activate

End Sub

Mike F
 
Mr Mike this code is not applied. I send you example

In Sheet1 there are 3 fields
A1: Invoice#
B1 DATE
C1: Qty
when I input in sheet 1 such as Invoice#: 1245, DATE: 18-1-2010, QTY:12.
Then i want these input fielsd will save in sheet2 serial wise when i click
 
Assuming both sheets have headers in row 1, this will transfer data from the
last used row, columns A:C of Sheet1 to the next empty row, columns A:C of
sheet2.

Private Sub CommandButton1_Click()
Dim LRow As Long
Dim Src As Range, Dest As Range

LRow = Sheet2.Cells(Rows.Count, "A").End(xlUp).Row
If IsEmpty(Sheet2.Cells(LRow, 1)) Then
LRow = LRow
Else
LRow = LRow + 1
End If
Set Dest = Sheet2.Range("A" & LRow & ":C" & LRow)
LRow = Sheet1.Cells(Rows.Count, "A").End(xlUp).Row
Set Src = Sheet1.Range("A" & LRow & ":C" & LRow)
Dest.Value = Src.Value
End Sub

Mike F
 
Back
Top