View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Doug Glancy Doug Glancy is offline
external usenet poster
 
Posts: 770
Default Cell address nearest to screen coordinates

Quartz,

Here's a start at least:

Sub test()

Dim r As Long, c As Long
Dim target_left As Double, target_top As Double
Dim current_left As Double, current_top As Double

c = 1
r = 1
current_left = 0
current_top = 0

target_top = 282.5
target_left = 436.27

While current_left < target_left
If Sheet1.Cells(r, c).Left < target_left Then
c = c + 1
Else
While current_top < target_top
If Sheet1.Cells(r, c).Top < target_top Then
r = r + 1
Else
With Sheet1.Cells(r, c)
.Select
MsgBox .Address & vbCr & _
"Top = " & .Top & "," & " Left = " & .Left
Exit Sub
End With
End If
Wend
End If
Wend

End Sub

hth,

Doug Glancy

"quartz" wrote in message
...
Suppose I have a pair of screen coordinates as follows:

Top = 282.5 and Left = 436.27

How can I obtain the address of the cell that is on or nearest to these
coodinates? (doesn't need to be "exact" just close).

TIA