ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   No of columns in range (https://www.excelbanter.com/excel-programming/279072-no-columns-range.html)

Ron McCormick[_2_]

No of columns in range
 
I have a procedure with the following lines of code in it:

Range(Selection, ActiveCell.SpecialCells
(xlLastCell)).Select
Selection.ClearContents
ActiveCell.Offset(-1, 0).Range("A1").Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Copy
ActiveCell.SpecialCells(xlLastCell).Select
ActiveCell.Offset(0, -36).Select
Range(Selection, Selection.End(xlUp)).Select

The "36" in the penultimate row represents, currently, the
number of columns from the column of the activecell in the
first row of code and the column of the last active cell
on the worksheet. How can I replace the "36" with some
code that represents the number of columns dynamically?

TIA
Ron

Tom Ogilvy

No of columns in range
 
easier would be

change
ActiveCell.Offset(0, -36).Select

to

Cells(activecell.row,1).Select

--
Regards,
Tom Ogilvy

"Ron McCormick" wrote in message
...
I have a procedure with the following lines of code in it:

Range(Selection, ActiveCell.SpecialCells
(xlLastCell)).Select
Selection.ClearContents
ActiveCell.Offset(-1, 0).Range("A1").Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Copy
ActiveCell.SpecialCells(xlLastCell).Select
ActiveCell.Offset(0, -36).Select
Range(Selection, Selection.End(xlUp)).Select

The "36" in the penultimate row represents, currently, the
number of columns from the column of the activecell in the
first row of code and the column of the last active cell
on the worksheet. How can I replace the "36" with some
code that represents the number of columns dynamically?

TIA
Ron





All times are GMT +1. The time now is 12:06 AM.

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