Hi everyone,
I am very new to VBA and I have a question concerning the following code that was written for use on an excel worksheet.
I want to cut a row from a table (tb_Datenbank) and paste it in a table on another worksheet (tb_Datenbank1) in the same workbook.
The code works fine but I have to make an input " x" in front of the row I want to copy, in order to get this code to work. Besides I have to put the code in the code window of the worksheet, as it is a private sub
My aim now is to have a button (makro) that is doing the same thing but without making an entry "x". I would just like to position my cursor in a cell within that row, push the button with the makro and have the same
result. Is this possible? Can anyone help me with the new code for this. Thanks, Tanja
Private Sub Worksheet_Change(ByVal Target As Range)
Dim lngErste As Long
If Target.Column = 1 Then
If Target.Count = 1 Then
If UCase(Target) = "X" Then
With Worksheets("Archiv")
lngErste = IIf(IsEmpty(.Cells(.Rows.Count, 1)), _
.Cells(.Rows.Count, 1).End(xlUp).Row, .Rows.Count) + 1
Rows(Target.Row).Copy
.Cells(lngErste, 1).PasteSpecial Paste:=xlValues
Rows(Target.Row).Delete shift:=xlUp
End With
End If
End If
End If
End Sub
I am very new to VBA and I have a question concerning the following code that was written for use on an excel worksheet.
I want to cut a row from a table (tb_Datenbank) and paste it in a table on another worksheet (tb_Datenbank1) in the same workbook.
The code works fine but I have to make an input " x" in front of the row I want to copy, in order to get this code to work. Besides I have to put the code in the code window of the worksheet, as it is a private sub
My aim now is to have a button (makro) that is doing the same thing but without making an entry "x". I would just like to position my cursor in a cell within that row, push the button with the makro and have the same
result. Is this possible? Can anyone help me with the new code for this. Thanks, Tanja
Private Sub Worksheet_Change(ByVal Target As Range)
Dim lngErste As Long
If Target.Column = 1 Then
If Target.Count = 1 Then
If UCase(Target) = "X" Then
With Worksheets("Archiv")
lngErste = IIf(IsEmpty(.Cells(.Rows.Count, 1)), _
.Cells(.Rows.Count, 1).End(xlUp).Row, .Rows.Count) + 1
Rows(Target.Row).Copy
.Cells(lngErste, 1).PasteSpecial Paste:=xlValues
Rows(Target.Row).Delete shift:=xlUp
End With
End If
End If
End If
End Sub