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
[vba]
Selection.Copy Sheets(2).Range("A1")
[/vba]
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
[vba]
Selection.Copy Sheets(2).Range("A1")
[/vba]
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.
[vba]
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
[/vba]
[vba]
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
[/vba]
PLS DO NOT PM; OPEN A THREAD INSTEAD!!!
1) Posting Code
[CODE]PasteYourCodeHere[/CODE]
(or paste your code, select it, click # button)
2) Uploading File(s)
Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.
3) Testing the Codes
always back up your files before testing the codes.
4) Marking the Thread as Solved
from Thread Tools (on the top right corner, above the first message)
I tried this code too
[VBA]
If Not Selection.Parent.Name = Sheets(2).Name Then Selection.Copy Sheets(2).Range("A1")
[/VBA]
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