J
Jack Sons
Hi all,
In sheet1 I have numbers in column A, the same numbers in sheet2 column B.
I want that doubleclicking on a number in column A of sheet1 results in
going to the cell of sheet2, column B that is right of the cell in column B
that has the same number in it (without highlighting anything) If I click on
the tab of sheet1 I should see the cursor still on the cell where I
doubleclicked, nothing highlighted.
I thought the following code would work, but it doesn't. It stops at
Sheets("Blad2").Columns("B:B").Select
with an errormessage that says that the method select will not work.
What did I wrong? Was I going in the right direction anyway? Should the
second half of the code (after the find operation) be changed into better
code? (I think so).
Your help will be appreciated very much.
Jack Sons
The Netherlands
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
Dim myValue As Double
Dim NewRow As Integer
Dim NewColumn As Integer
If Target.Cells.Count > 1 Then Exit Sub
If Intersect(Target, Me.Range("A:H")) Is Nothing Then Exit Sub
If Target.HasFormula Then Exit Sub
If Application.IsNumber(Target.Value) Then
myValue = Target.Value
Sheets("Blad2").Columns("B:B").Select
Selection.Find(What:=myValue, After:=ActiveCell, LookIn:=xlFormulas,
LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext,
MatchCase:= _
False).Activate
NewRow = ActiveCell.Row
NewColumn = ActiveCell.Column
Sheets("Blad2").Range(Cells(NewRow, NewColumn + 1), Cells(NewRow,
NewColumn + 1)).Select
End If
End Sub
In sheet1 I have numbers in column A, the same numbers in sheet2 column B.
I want that doubleclicking on a number in column A of sheet1 results in
going to the cell of sheet2, column B that is right of the cell in column B
that has the same number in it (without highlighting anything) If I click on
the tab of sheet1 I should see the cursor still on the cell where I
doubleclicked, nothing highlighted.
I thought the following code would work, but it doesn't. It stops at
Sheets("Blad2").Columns("B:B").Select
with an errormessage that says that the method select will not work.
What did I wrong? Was I going in the right direction anyway? Should the
second half of the code (after the find operation) be changed into better
code? (I think so).
Your help will be appreciated very much.
Jack Sons
The Netherlands
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
Dim myValue As Double
Dim NewRow As Integer
Dim NewColumn As Integer
If Target.Cells.Count > 1 Then Exit Sub
If Intersect(Target, Me.Range("A:H")) Is Nothing Then Exit Sub
If Target.HasFormula Then Exit Sub
If Application.IsNumber(Target.Value) Then
myValue = Target.Value
Sheets("Blad2").Columns("B:B").Select
Selection.Find(What:=myValue, After:=ActiveCell, LookIn:=xlFormulas,
LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext,
MatchCase:= _
False).Activate
NewRow = ActiveCell.Row
NewColumn = ActiveCell.Column
Sheets("Blad2").Range(Cells(NewRow, NewColumn + 1), Cells(NewRow,
NewColumn + 1)).Select
End If
End Sub