View Full Version : [SOLVED:] Set Range as a single cell relative to active cell
Kingwi11y
09-14-2013, 11:18 AM
Hi
When I try and define a range as a single cell relative to the current cell, I get an error that the range failed:
If target.Cells.Column = 2 Then
If target.Cells.Row > 3 Then
If target.Cells.Count = 1 Then
Range(ActiveCell.Offset(0, 1)).Select
End If
End If
End If
I know I could set the range and then offset the focus after but I want to define the range as a cell relative to the current one
patel
09-14-2013, 11:34 AM
If target.Cells.Column = 2 and target.Cells.Row > 3 and target.Cells.Count = 1 Then Target.Offset(0, 1)).Select
HaHoBe
09-14-2013, 11:03 PM
hi, patel,
there´s a closing bracket too much behind the Offset-Command, and due to the fact that the limitation for Target is 1 you may omitt Cells for Target.
If Target.Column = 2 And Target.Row > 3 And Target.Count = 1 Then Target.Offset(0, 1).Select
With Target
If .Count = 1 Then
If .Column = 2 And .Row > 3 Then
Application.EnableEvents = False
.Offset(0, 1).Select
Application.EnableEvents = True
End If
End If
End With
Ciao,
Holger
Kingwi11y
09-29-2013, 03:35 AM
Hi Patel and Holger - thanks for your replies!
Very nice way to abbreviate the code
It wasn't what I was after but it showed me I was complicating things and a nice simple way of sorting it
I was trying to change the value of another cell - and thought I had to make that cell a range before i could change the value of it
But when I saw your code, I realised all i had to do was:
target.offset(0,1).value=...
It explains why it wouldn't let me set a single cell as a range --> because there is no point making a single cell range
Many thanks!
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.