ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Loop Through Highlighted Range (https://www.excelbanter.com/excel-programming/318993-loop-through-highlighted-range.html)

ChrisR

Loop Through Highlighted Range
 
am trying to write something that will allow me to select a range of cells
(mostly just within 1 column, but maybe hundreds of rows deep). Then I want
to loop through each cell in the selection and at each cell perform
"ActiveCell.FormulaR1C1 = ActiveCell.ValueI " to basically activate the cell.
I do this for fields of info pulled from a Financial LAN where they come
down as text. Use to have this written in personal macro file, but hard
drive crashed and dont remember how I wrote it years ago.

Any help would be appreciated. Here is my non working attempt...

Sub Activate()

' Keyboard Shortcut: Ctrl+Shift+Z

Dim cell As Range
Dim myrange As Range

Range(ActiveSheet.Range).Name = "myrange"

For Each cell In Range("myrange")

ActiveCell.FormulaR1C1 = ActiveCell.Value
ActiveCell.Offset(rowOffset:=1, columnOffset:=0).Activate
Next cell

Selection.End(xlUp).Select
End Sub

Frank Kabel

Loop Through Highlighted Range
 
Hi
try using

with selection
..value=.value
end with

--
Regards
Frank Kabel
Frankfurt, Germany

ChrisR wrote:
am trying to write something that will allow me to select a range of
cells (mostly just within 1 column, but maybe hundreds of rows deep).
Then I want to loop through each cell in the selection and at each
cell perform "ActiveCell.FormulaR1C1 = ActiveCell.ValueI " to
basically activate the cell. I do this for fields of info pulled from
a Financial LAN where they come down as text. Use to have this
written in personal macro file, but hard drive crashed and dont
remember how I wrote it years ago.

Any help would be appreciated. Here is my non working attempt...

Sub Activate()

' Keyboard Shortcut: Ctrl+Shift+Z

Dim cell As Range
Dim myrange As Range

Range(ActiveSheet.Range).Name = "myrange"

For Each cell In Range("myrange")

ActiveCell.FormulaR1C1 = ActiveCell.Value
ActiveCell.Offset(rowOffset:=1, columnOffset:=0).Activate
Next cell

Selection.End(xlUp).Select
End Sub





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

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