ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   to change the macros as per active cell and range (https://www.excelbanter.com/excel-discussion-misc-queries/238826-change-macros-per-active-cell-range.html)

pol

to change the macros as per active cell and range
 
Hi all,
Need your help to change the formula .
Columns("Q:Q").Select
Range("Q1").Activate

How I can change the above macros with active cell and active cell range

For example

If the cursor is in A1column the macro should be

COlumn(A:A).select
Range("A1).activate

If the cursor is in K column the macro should be

COlumn(K:K).select
Range("K1).activate

With thanks

Pol



Jacob Skaria

to change the macros as per active cell and range
 
Try

Columns(ActiveCell.Column).Select
Cells(1, ActiveCell.Column).Activate

If this post helps click Yes
---------------
Jacob Skaria


"pol" wrote:

Hi all,
Need your help to change the formula .
Columns("Q:Q").Select
Range("Q1").Activate

How I can change the above macros with active cell and active cell range

For example

If the cursor is in A1column the macro should be

COlumn(A:A).select
Range("A1).activate

If the cursor is in K column the macro should be

COlumn(K:K).select
Range("K1).activate

With thanks

Pol



Dave Peterson

to change the macros as per active cell and range
 
Another one:

With ActiveCell.EntireColumn
.Select
.Cells(1).Activate
End With

In my simple tests, I didn't even need the .activate statement, but I'd keep
it. It makes the code more self-documenting.

pol wrote:

Hi all,
Need your help to change the formula .
Columns("Q:Q").Select
Range("Q1").Activate

How I can change the above macros with active cell and active cell range

For example

If the cursor is in A1column the macro should be

COlumn(A:A).select
Range("A1).activate

If the cursor is in K column the macro should be

COlumn(K:K).select
Range("K1).activate

With thanks

Pol


--

Dave Peterson


All times are GMT +1. The time now is 03:31 PM.

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