Selecting and copying data

SlinkyWheels

Board Regular
Joined
Jan 5, 2007
Messages
217
Hi

Is it possible to copy a row of data from "Sheet 1" and paste it into "Sheet 2" without actually selecting "Sheet 1"

ie, I am trying to write some code that will work whilst in "Sheet 2" but never actually goes into "Sheet 1"

Does this make any sense?
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Code:
Sheets("Sheet1").Range("A1:A100").Copy Destination:=Sheets("Sheet2").Range("A1")
 
Upvote 0
Hi
try
Code:
Worksheets("sheet1").Rows(51).Copy
Rows(12).PasteSpecial
pastes row 51 of sheet 1 to 12th row of sheet2 (active sheet)
Ravi
 
Upvote 0
Thanks both, really good. :)

This now leads me to another problem.

My code is needed on a "Worksheet_activate" macro.

The trouble is the first part requires me do a loop through "Sheet 1", which I can do but, I cant get the loop to start in cell "B12" without selecting "Sheet 1" first. If I do this, I would need to select "Sheet 2" at the end of the macro and this would initiate the macro all over again.

So........basically......all I am trying to do is set "B12" as the start of my loop without actually going into "Sheet 1" do do it.

Can anyone help?
 
Upvote 0
Depends what you're trying to do, but I'd have thought the following would work...

Code:
With Sheets("Sheet1").Range("B1")
'your code goes here, (eg .Copy)
End With
 
Upvote 0
Hi

That is the code I tried but it is not starting from "B12".

It is looping from wherever the active cell is on "Sheet 1".

Very confusing.
 
Upvote 0
If you need help rewriting your code, post the offending portion and explain what you're trying to do.
 
Upvote 0
:oops: Suddenly realised I had not posted my code. I need more coffee!!

Ok, here is the code.

Code:
Private Sub Worksheet_Activate()

Dim Proj As Variant

n = ActiveSheet.Name

Set Proj = Range("B11")
Proj.Select
ActiveCell.Offset(0, 29).Select
Sheets("POST APPROVAL").Unprotect "Password"

With Sheets("POST APPROVAL").Range("B12")
Do Until ActiveCell = Blank

If ActiveCell.Value = Proj Then
If ActiveCell.Offset(0, -1).Value = "Post Approval" Then
GoTo Dunc
Exit Sub
End If
End If
ActiveCell.Offset(1, 0).Select
Loop
End With
Dunc:
ActiveCell.Offset(0, 29).Activate
Sheets("POST APPROVAL").Range("AE12").Resize(1, 121).Copy
Sheets(n).Range(Proj).Offset(0, 29).PasteSpecial Paste:=xlValues

End Sub
This basically runs when the sheet (Sheet 2) is selected.
Then unprotects the "Post Approval" sheet, finds "Proj" on this sheet, then offsets, then resizes, copies and finally pastes back onto Sheet 2
 
Upvote 0
Without seeing the layout of your file, I'm struggling to understand your code (I think the resize statement would be redundant if you used a dynamic range), but this should be more efficient

Code:
Private Sub Worksheet_Activate()
Dim Proj As Variant
Dim n As String
Dim i As Long, End_Row As Long

With Application
.ScreenUpdating = False
.EnableEvents = False
End With

n = ActiveSheet.Name

Set Proj = Range("B11")

With Sheets("POST APPROVAL")
.Unprotect "Password"

End_Row = .Range("B12").End(xlDown).Row

For i = 12 To End_Row

If .Cells(i, 2).Value = Proj And Cells(i, 1).Value = "Post Approval" Then
Sheets("POST APPROVAL").Range("AE12").Resize(1, 121).Copy
Sheets(n).Range(Proj).Offset(0, 29).PasteSpecial xlValues

Exit Sub
End If

Next i
End With

End Sub
 
Upvote 0

Forum statistics

Threads
1,214,648
Messages
6,120,726
Members
448,987
Latest member
marion_davis

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top