W
whitethomas12
I have a quick question.
I have been trying to copy data from one worksheet and inserting it
into another. if I just want to paste it into the other then it will
work, but if I have the code insert rows first then it fails.
The following is my code:
Dim x As String
Range("A2").Select
Do While ActiveCell.Value <> ""
Dim nDataRange As Range
Dim InsQuan As Long
x = ActiveCell.Value
Sheets("Sheet1").Select
Set nDataRange = Nothing
Range("J1").Select
Do While ActiveCell.Value <> ""
If ActiveCell.Value = x Then
InsQuan = InsQuan + 1
If nDataRange Is Nothing Then
Set nDataRange = ActiveCell
Else
Set nDataRange = Union(nDataRange, ActiveCell)
End If
End If
ActiveCell.Offset(1, 0).Select
Loop
'nDataRange.EntireRow.Select
nDataRange.EntireRow.Copy
Sheets("Sheet4").Select
ActiveCell.Offset(1, 0).Select
ActiveCell.Insert shift:=xlDown
ActiveSheet.Paste
' ActiveCell.Offset(1, 0).Range("A1:A" & InsQuan).Select
'Selection.Insert Shift:=xlDown
''ActiveCell.Select
''ActiveCell.Offset(1, 0).Insert shift:=xlDown
''ActiveCell.Insert shift:=xlDown
''ActiveCell.Offset(1, 0).Select
''Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone,
SkipBlanks:= _
'' False, Transpose:=False
''Selection.Insert shift:=xlDown
'ActiveSheet.Paste
ActiveCell.Offset(1, 0).Select
Loop
'ActiveCell.Offset(1, 0).Select
So basically what my code is doing is selecting a name from the target
worksheet and then looping through the worksheet with the data, then
it is trying to insert rows just under the search criteria in the
target page. From here I would like it to insert the data without
deleting all of the other data.
As you can tell by my commit outs of vb code. I have tried several
options
Will someone please assist me
Thank you for all of your help
I have been trying to copy data from one worksheet and inserting it
into another. if I just want to paste it into the other then it will
work, but if I have the code insert rows first then it fails.
The following is my code:
Dim x As String
Range("A2").Select
Do While ActiveCell.Value <> ""
Dim nDataRange As Range
Dim InsQuan As Long
x = ActiveCell.Value
Sheets("Sheet1").Select
Set nDataRange = Nothing
Range("J1").Select
Do While ActiveCell.Value <> ""
If ActiveCell.Value = x Then
InsQuan = InsQuan + 1
If nDataRange Is Nothing Then
Set nDataRange = ActiveCell
Else
Set nDataRange = Union(nDataRange, ActiveCell)
End If
End If
ActiveCell.Offset(1, 0).Select
Loop
'nDataRange.EntireRow.Select
nDataRange.EntireRow.Copy
Sheets("Sheet4").Select
ActiveCell.Offset(1, 0).Select
ActiveCell.Insert shift:=xlDown
ActiveSheet.Paste
' ActiveCell.Offset(1, 0).Range("A1:A" & InsQuan).Select
'Selection.Insert Shift:=xlDown
''ActiveCell.Select
''ActiveCell.Offset(1, 0).Insert shift:=xlDown
''ActiveCell.Insert shift:=xlDown
''ActiveCell.Offset(1, 0).Select
''Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone,
SkipBlanks:= _
'' False, Transpose:=False
''Selection.Insert shift:=xlDown
'ActiveSheet.Paste
ActiveCell.Offset(1, 0).Select
Loop
'ActiveCell.Offset(1, 0).Select
So basically what my code is doing is selecting a name from the target
worksheet and then looping through the worksheet with the data, then
it is trying to insert rows just under the search criteria in the
target page. From here I would like it to insert the data without
deleting all of the other data.
As you can tell by my commit outs of vb code. I have tried several
options
Will someone please assist me
Thank you for all of your help