Sub add_product()
' add_product Macro
' ADD PRODUCT MACRO
' TeachExcel.com
' Takes data from one worksheet and stores in in the next empty row on another worksheet.
Dim sourceSheet As Worksheet
Dim dataSheet As Worksheet
Dim nextRow As Long
' Make some sheet variables so we can use those instead of hard-coding sheet references in the code.
Set sourceSheet = Sheets("add product")
Set dataSheet = Sheets("products")
' Get the next empty row from the Data sheet.
nextRow = dataSheet.Range("A" & dataSheet.Rows.Count).End(xlUp).Offset(1).Row
' Input the form values into the Data sheet.
dataSheet.Cells(nextRow, 1).Value = sourceSheet.Range("J5").Value
dataSheet.Cells(nextRow, 2).Value = sourceSheet.Range("J7").Value
dataSheet.Cells(nextRow, 3).Value = sourceSheet.Range("J9").Value
dataSheet.Cells(nextRow, 4).Value = sourceSheet.Range("J11").Value
dataSheet.Cells(nextRow, 5).Value = sourceSheet.Range("J13").Value
'Clear Data
sourceSheet.Range("J7").Value = ""
sourceSheet.Range("J9").Value = ""
sourceSheet.Range("J11").Value = ""
sourceSheet.Range("J13").Value = ""
End Sub
I want to add the new Row inside the table enter image description here But as you see in the photo next, the data going outsite the table enter image description here