Reputation: 11
I have two sheets in which I insert data. In sheet1 I have data in column1 and a button.
If I click the button the data will be transfered to sheet2 in row1. Afterwards the user can add captions in column1 and set "x" to the table to sort the captions to the headlines in row1.
The code for that part is not very hard and works perfectly fine.
Private Sub CommandButton1_Click()
Zeile = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row
For i = 2 To Zeile
Sheets("2").Cells(1, i) = Sheets("1").Cells(i, 1)
Next i
End Sub
My question is now how I can secure the entered data? If someone is entering in Sheet1 for example an G in between B and C and presses the button a second time it shall not mess up the "x" in Sheet2. Change in Sheet1 So the column of G has to stay empty but the columns of C,D,E,F shall still have their "x". (In the following picture the inserted Column is highlighted green. Change in Sheet2 after clicking the button in Sheet1 The user can enter as many rows as he/she wants in sheet1 and it shall be updated by clicking at the button. Do you have an idea how I could realize that?
Thanks!
Upvotes: 0
Views: 25
Reputation: 39
If I understand you correctly, you could use If statement:
For i = 2 To Zeile
If Sheets("2").Cells(1, i) = "" Then
Sheets("2").Cells(1, i) = Sheets("1").Cells(i, 1)
End If
Next i
Upvotes: 1