ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Worksheet Functions (https://www.excelbanter.com/excel-worksheet-functions/)
-   -   VB Script in Excel to copy a row (https://www.excelbanter.com/excel-worksheet-functions/95254-vbulletin-script-excel-copy-row.html)

traceydee150

VB Script in Excel to copy a row
 
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


Alok

VB Script in Excel to copy a row
 
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

traceydee150 wrote:
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



traceydee150

VB Script in Excel to copy a row
 
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?


Alok wrote:
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

traceydee150 wrote:
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



traceydee150

VB Script in Excel to copy a row
 
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?


Alok wrote:
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

traceydee150 wrote:
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



traceydee150

VB Script in Excel to copy a row
 
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


traceydee150 wrote:
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?


Alok wrote:
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

traceydee150 wrote:
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




All times are GMT +1. The time now is 09:49 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com