View Full Version : Solved: Question About copy Selection
Nader
02-10-2011, 01:23 AM
I tried this code to copy each selction cells to the sheets2. the probelm that i faced it's word with sheets2 too . I want to work for all sheets except sheets2
Selection.Copy Sheets(2).Range("A1")
mancubus
02-10-2011, 07:55 AM
when you activate a worksheet, previous selection will be copied to this sheet cell A1, if sheet name is not "Sheet2".
first code works if the selection contains more than one cell.
Private Sub Workbook_SheetActivate(ByVal Sh As Object)
Dim wks As Worksheet
For Each wks In Worksheets
If wks.Name <> "Sheet2" Then
If Selection.Rows.Count > 1 Or Selection.Columns.Count > 1 Then
Selection.Copy wks.Range("A1")
End If
End If
Next
End Sub
Private Sub Workbook_SheetActivate(ByVal Sh As Object)
Dim wks As Worksheet
For Each wks In Worksheets
If wks.Name <> "Sheet2" Then
Selection.Copy wks.Range("A1")
End If
Next
End Sub
Nader
02-10-2011, 08:46 AM
I tried this code too
If Not Selection.Parent.Name = Sheets(2).Name Then Selection.Copy Sheets(2).Range("A1")
but the problem that I faced with my code and your first code is that when I select the cells in sheet1 and then select sheet2 to see the data it didn't print them only if I select sheets1 and then sheet2 ( I think because of the "Workbook_SheetActivate" Event
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.