I want to write a program that saves the text in textbox to an Excel file using a loop because I want to insert multiple text into Excel. I found codes but it only overwrite
Your main concern is to find the last used row in your excel.
For that you can use
Excel.Range usedRange = xlWorkSheet .UsedRange;
Excel.Range _lastCell= usedRange.SpecialCells(Excel.XlCellType.xlCellTypeLastCell,
Type.Missing);
int _lastRow= lastCell.Row; // Gives you the last used row in your Excel sheet
int _lastCol = lastCell.Column; // Give you the last used column
_lastRow++; // To get the next row
for (int i=_lastRow; i<=_lastrow+6; i++) // Set your i value to _lastRow
{
xlWorkSheet.Cells[i, 1] = textBox1.Text;
xlWorkSheet.Cells[i, 2] = textBox2.Text;
xlWorkSheet.Cells[i, 3] = textBox3.Text;
xlWorkSheet.Cells[i, 4] = textBox4.Text;
}