ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Selecting simple range relative to the active cell. (https://www.excelbanter.com/excel-programming/378391-selecting-simple-range-relative-active-cell.html)

jmac68

Selecting simple range relative to the active cell.
 
I need to have my macro select the 9 cells starting with the active cell in
column B and extending 8 cells to the right. I am doing this as a custom
"copy range" funtion in a macro. I do not want an absolute reference for the
range. It should be relative to any ACTIVE cell in column B.

If there is no ACTIVE cell in column B, then I would like to return an error
message "Wrong Column Selected" with and "O.K." button.

Jim Thomlinson

Selecting simple range relative to the active cell.
 
Give this a try...

Sub SelectRange()

If ActiveCell.Column = 2 Then
ActiveCell.Resize(1, 9).Select
Else
MsgBox "Sorry. You are in the wrong column...", _
vbInformation, "Wrong Column"
End If
End Sub

--
HTH...

Jim Thomlinson


"jmac68" wrote:

I need to have my macro select the 9 cells starting with the active cell in
column B and extending 8 cells to the right. I am doing this as a custom
"copy range" funtion in a macro. I do not want an absolute reference for the
range. It should be relative to any ACTIVE cell in column B.

If there is no ACTIVE cell in column B, then I would like to return an error
message "Wrong Column Selected" with and "O.K." button.


Steve Yandl

Selecting simple range relative to the active cell.
 
Dim newRng As Range
If Not ActiveCell.Column = 2 Then
MsgBox "You selected a cell in the wrong column"
Else
rowStr = CStr(ActiveCell.Row)
Set newRng = Range("$B$" & rowStr & ":$J$" & rowStr)
newRng.Select
End If

Steve


"jmac68" wrote in message
...
I need to have my macro select the 9 cells starting with the active cell in
column B and extending 8 cells to the right. I am doing this as a custom
"copy range" funtion in a macro. I do not want an absolute reference for
the
range. It should be relative to any ACTIVE cell in column B.

If there is no ACTIVE cell in column B, then I would like to return an
error
message "Wrong Column Selected" with and "O.K." button.





All times are GMT +1. The time now is 12:13 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com