VB code to find the selected cell

  • Thread starter Thread starter Andrew
  • Start date Start date
A

Andrew

I want the VB code to see if the mouse selects particular
cells... (somewhere in the column range (B7 : B47)

If one of these cells is selected then the ROW of the
selected cell will be used in another part of the prgram
to display.

Does anyone know the code to achieve this??

Yours hopefully
ANdrew
 
Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
if Not Intersect(Target,Range("B7:B47")) is nothing Then
' selection intersects with at least one cell in B7:B47
' put code here or a call to the existing procedure.
end if

End Sub

Right click on the sheet module and select view code. Put in code like the
above. This code fires everytime the user selects a cell.
 
The following should give you a good start. Since I'm not sure what
you want to do with the selected row I've just selected it and left it
at that.

Regards,
Andrew

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim strRowAddress As String

If Target.Column = 2 Then
If Target.Row >= 7 And Target.Row <= 47 Then
'MsgBox Target.Address
strRowAddress = Target.Row & ":" & Target.Row
Range(strRowAddress).Select
End If
End If
End Sub
 
Back
Top