code is not to work on sheet1

  • Thread starter Thread starter Allan R Jeffery
  • Start date Start date
A

Allan R Jeffery

Hello to all.

If possible could someone help here.
This workbook is a bookin sheet for guests.

Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal
Target As Range)

' VB TO COPY CONTENTS FROM LAST SHEET TO THIS ONE
If ActiveCell.Row < 11 Then Exit Sub
If ActiveCell.Row > 64 Then Exit Sub
If ActiveCell.Column > 1 Then Exit Sub
ActiveSheet.Unprotect
Sheets(ActiveSheet.Index - 1).Rows(ActiveCell.Row).Copy

ActiveSheet.Paste

end sub

As you can see here, this bit of code copies the row from previous
sheet over the active sheet. This also works even when i am on sheet1,
however there should be nothing to copy. Is it possible for the this
code to look at what sheet it is on and if sheet1 then not execute.

Many thanks Allan
 
Allan said:
Hello to all.

If possible could someone help here.
This workbook is a bookin sheet for guests.

Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal
Target As Range)

' VB TO COPY CONTENTS FROM LAST SHEET TO THIS ONE
If ActiveCell.Row < 11 Then Exit Sub
If ActiveCell.Row > 64 Then Exit Sub
If ActiveCell.Column > 1 Then Exit Sub
ActiveSheet.Unprotect
Sheets(ActiveSheet.Index - 1).Rows(ActiveCell.Row).Copy

ActiveSheet.Paste

end sub

As you can see here, this bit of code copies the row from previous
sheet over the active sheet. This also works even when i am on sheet1,
however there should be nothing to copy. Is it possible for the this
code to look at what sheet it is on and if sheet1 then not execute.

Many thanks Allan


Hi Allan,

try this:

Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal
Target As Range)

' VB TO COPY CONTENTS FROM LAST SHEET TO THIS ONE

If ActiveSheet.Name = "Sheet1" Then Exit Sub

If ActiveCell.Row < 11 Then Exit Sub
If ActiveCell.Row > 64 Then Exit Sub
If ActiveCell.Column > 1 Then Exit Sub
ActiveSheet.Unprotect
Sheets(ActiveSheet.Index - 1).Rows(ActiveCell.Row).Copy

ActiveSheet.Paste

end sub




--
Hope I helped you.

Thanks in advance for your feedback.

Ciao

Franz Verga from Italy
 
Excel gives you the sh and the activecell, so why not use them?

Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target
As Range)

' VB TO COPY CONTENTS FROM LAST SHEET TO THIS ONE

If Sh.Name = "Sheet1" Then Exit Sub

If Target.Cells(1, 1).Row < 11 Then Exit Sub
If Target.Cells(1, 1).Row > 64 Then Exit Sub
If Target.Cells(1, 1).Column > 1 Then Exit Sub
ActiveSheet.Unprotect
Sheets(Sh.Index - 1).Rows(Target.Cells(1, 1).Row).Copy

Sh.Paste

End Sub




--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"Allan R Jeffery"
 
Back
Top