When I use the code below (to copy from sheet 2 to sheet 1, certain cells), it works fine. If I change the names of the sheets, (and amend the code), I get the error message. Can anyone put some light on this.
(thanks to Zathras for code)
Thanks
Allen
Sheet1:
Option Explicit
Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
If Target.Count = 1 Then
Selection1 = "Sheet1!" + Target.Address
End If
End Sub
Sheet2:
Option Explicit
Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
If Target.Count = 1 Then
Selection2 = "Sheet2!" + Target.Address
End If
End Sub
Insert a module:
Module1:
Option Explicit
Public Selection1 As String
Public Selection2 As String
Sub CopyThreeCells()
Dim FromCell As Range
Dim ToCell As Range
Set FromCell = Range(Selection2)
Set ToCell = Range(Selection1)
ToCell.Value = FromCell.Value
ToCell.Offset(-10, 0).Value = FromCell.Offset(-10, 0).Value
ToCell.Offset(-20, 0).Value = FromCell.Offset(-20, 0).Value
Set ToCell = Nothing
Set FromCell = Nothing
End Sub
Select Sheet2 and enter the following three cells:
E40: 'This is from E40
E50: 'This is from E50
E60: 'This is from E60
(thanks to Zathras for code)
Thanks
Allen
Sheet1:
Option Explicit
Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
If Target.Count = 1 Then
Selection1 = "Sheet1!" + Target.Address
End If
End Sub
Sheet2:
Option Explicit
Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
If Target.Count = 1 Then
Selection2 = "Sheet2!" + Target.Address
End If
End Sub
Insert a module:
Module1:
Option Explicit
Public Selection1 As String
Public Selection2 As String
Sub CopyThreeCells()
Dim FromCell As Range
Dim ToCell As Range
Set FromCell = Range(Selection2)
Set ToCell = Range(Selection1)
ToCell.Value = FromCell.Value
ToCell.Offset(-10, 0).Value = FromCell.Offset(-10, 0).Value
ToCell.Offset(-20, 0).Value = FromCell.Offset(-20, 0).Value
Set ToCell = Nothing
Set FromCell = Nothing
End Sub
Select Sheet2 and enter the following three cells:
E40: 'This is from E40
E50: 'This is from E50
E60: 'This is from E60