VB Script in Excel to copy a row

T

traceydee150

I've been using the sample spreadsheets from contexture.com. to do my
projects. Helpful doesn't even come close. However, the sample file
called ProductOrderList has a code that when you move over a cell in
column g, it automatically puts an x in the cell, which copies this row
to another sheet within the file. I'm trying to edit the code, to
where you have to put an x in the cell, not just move over it and I'm
not able to do it. Any help??? Here's the code:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Column = 7 And Target.Row > 6 Then
If Cells(Target.Row, 1).Value <> "" Then
Target.Value = "X"
MoveRow
'MsgBox "Row has been copied"
End If
End If
End Sub

As Always, Thanks

TDee
 
A

Alok

Hi
You could try the following

Comment out the Selection Change event.

In the Change event of the worksheet enter the following code:

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 7 And Target.Row > 6 Then
If Target.Cells(1).value = "x" Then
MoveRow
'MsgBox "Row has been copied"
End If
End If
End Sub

Alok
 
T

traceydee150

Thanks so much - that works - except.... once I put the "X" in the
cell, where ever the cursor ends up, weither it's by hitting enter or
clicking on another row to get out of the cell that's the info that
get's transferred over. IE: If I put an X in g7 and hit enter, row 8
populates in sheet 2, if I put an X in g7 and click onto b19, row 19
populates...... Is there something that can be adjusted?
 
T

traceydee150

Thanks so much - that works - except.... once I put the "X" in the
cell, where ever the cursor ends up, weither it's by hitting enter or
clicking on another row to get out of the cell that's the info that
get's transferred over. IE: If I put an X in g7 and hit enter, row 8
populates in sheet 2, if I put an X in g7 and click onto b19, row 19
populates...... Is there something that can be adjusted?
 
T

traceydee150

I found a macro:

Option Explicit

Sub MoveRow()
Dim wsOrder As Worksheet
Dim wsData As Worksheet
Dim r As Long

Set wsOrder = Worksheets("OrderForm")
Set wsData = Worksheets("Data Entry")
r = wsOrder.Cells(Rows.Count, 1).End(xlUp).Row + 1

ActiveCell.EntireRow.Copy Destination:=wsOrder.Cells(r, 1)

End Sub
 
Top