Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Excel Ranges

Hello Excel Experts.

How can I perameterise this code so it selects the row
and column of whichever cell I click on?

As the code stands it will only work if I click on C4 or
D13. Thanks for your help.

Private Sub Worksheet_SelectionChange(ByVal Target As
Range)


Dim CurrRow, CurrCol

CurrRow = ActiveCell.Row ' Get Row.
CurrCol = ActiveCell.Column ' Get Column.

If CurrRow = 4 And CurrCol = 3 Then
Range("4:4,C:C").Select
Range("C1").Activate
End If

If CurrRow = 13 And CurrCol = 4 Then
Range("13:13,D:D").Select
Range("D1").Activate
End If

End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Excel Ranges

Hi Ian,

This is how to do it.

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim rng As Range

With Target
Application.EnableEvents = False
Set rng = Union(.EntireRow, .EntireColumn)
rng.Select
Cells(1, .Column).Activate
Application.EnableEvents = True
End With

End Sub

I must admit though that I do not like the way that row 1 is selected, I
would have thought it better to activate the original target cell

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim rng As Range

With Target
Application.EnableEvents = False
Set rng = Union(.EntireRow, .EntireColumn)
rng.Select
.Activate
Application.EnableEvents = True
End With

End Sub

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Ian Wilson" wrote in message
...
Hello Excel Experts.

How can I perameterise this code so it selects the row
and column of whichever cell I click on?

As the code stands it will only work if I click on C4 or
D13. Thanks for your help.

Private Sub Worksheet_SelectionChange(ByVal Target As
Range)


Dim CurrRow, CurrCol

CurrRow = ActiveCell.Row ' Get Row.
CurrCol = ActiveCell.Column ' Get Column.

If CurrRow = 4 And CurrCol = 3 Then
Range("4:4,C:C").Select
Range("C1").Activate
End If

If CurrRow = 13 And CurrCol = 4 Then
Range("13:13,D:D").Select
Range("D1").Activate
End If

End Sub



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Excel Ranges

Private Sub Worksheet_SelectionChange(ByVal Target As Range

Dim CurrRow, CurrCol, A1ColRel, RCtoA
Static inUse As Boolea

If inUse Then Exit Su
inUse = Tru

CurrRow = ActiveCell.Row ' Get Row
CurrCol = ActiveCell.Column ' Get Column
A1ColRel = Application.ConvertFormula("R1" & "C" & CurrCol, xlR1C1, xlA1, xlAbsRowRelColumn
RCtoA1 = Left$(A1ColRel, InStr(2, A1ColRel, "$") - 1

Range(CurrRow & ":" & CurrRow & "," & RCtoA1 & ":" & RCtoA1).Selec
Range(RCtoA1 & "1").Activat

inUse = Fals
End Su


  #5   Report Post  
Posted to microsoft.public.excel.programming
No Name
 
Posts: n/a
Default Excel Ranges

Thanks guys.

I used this from Bob... nice one!

Private Sub Worksheet_SelectionChange(ByVal Target As
Range)
Dim rng As Range

With Target
Application.EnableEvents = False
Set rng = Union(.EntireRow, .EntireColumn)
rng.Select
.Activate
Application.EnableEvents = True
End With

End Sub


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Excel Ranges

.... and I'm glad that you are using #2, and not activating row 1<G

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

wrote in message
...
Thanks guys.

I used this from Bob... nice one!

Private Sub Worksheet_SelectionChange(ByVal Target As
Range)
Dim rng As Range

With Target
Application.EnableEvents = False
Set rng = Union(.EntireRow, .EntireColumn)
rng.Select
.Activate
Application.EnableEvents = True
End With

End Sub



  #7   Report Post  
Posted to microsoft.public.excel.programming
No Name
 
Posts: n/a
Default Excel Ranges

Yes, that would have been my next question ;-)

-----Original Message-----
.... and I'm glad that you are using #2, and not

activating row 1<G

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
how copy formula that contains ranges so ranges do not overlap Patty Excel Worksheet Functions 1 November 20th 08 04:15 PM
Ranges and Arrays in Excel VBA a.riva@UCL Excel Worksheet Functions 15 October 27th 07 12:15 AM
Excel and ranges Jason Excel Worksheet Functions 3 October 13th 05 04:15 AM
vba, excel, sum different ranges Danny Excel Worksheet Functions 6 August 9th 05 08:23 PM
Excel VBA 3D Ranges !p^&c88%B! Excel Programming 7 March 6th 04 01:25 AM


All times are GMT +1. The time now is 03:18 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"