ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Better way to apply change to column of values (https://www.excelbanter.com/excel-programming/310183-better-way-apply-change-column-values.html)

tod

Better way to apply change to column of values
 
I have a column with dates and times. I want to take the
date out. So I'm doing it like this:

For each Cell in ActiveSheet.Range("A2:A10000")
Cell.Value = Cell.Value - Int(Cell.Value)
Next Cell

This works, but it adds minutes to the procedure. Is
there a statement or other that will just make the change
to the entire range at once?

tod

JE McGimpsey

Better way to apply change to column of values
 
one way:

Dim vArr As Variant
Dim i As Long
With ActiveSheet.Range("A2:A10000")
vArr = .Value
For i = 1 To UBound(vArr)
vArr(i, 1) = Int(vArr(i, 1))
Next i
.Value = vArr
End With


In article ,
"Tod" wrote:

I have a column with dates and times. I want to take the
date out. So I'm doing it like this:

For each Cell in ActiveSheet.Range("A2:A10000")
Cell.Value = Cell.Value - Int(Cell.Value)
Next Cell

This works, but it adds minutes to the procedure. Is
there a statement or other that will just make the change
to the entire range at once?


tod

Better way to apply change to column of values
 
Wow! Big difference. Thanx.

-----Original Message-----
one way:

Dim vArr As Variant
Dim i As Long
With ActiveSheet.Range("A2:A10000")
vArr = .Value
For i = 1 To UBound(vArr)
vArr(i, 1) = Int(vArr(i, 1))
Next i
.Value = vArr
End With


In article ,
"Tod" wrote:

I have a column with dates and times. I want to take

the
date out. So I'm doing it like this:

For each Cell in ActiveSheet.Range("A2:A10000")
Cell.Value = Cell.Value - Int(Cell.Value)
Next Cell

This works, but it adds minutes to the procedure. Is
there a statement or other that will just make the

change
to the entire range at once?

.


Bernie Deitrick

Better way to apply change to column of values
 
Tod,

Using the worksheet is a good way:

If column B is blank:

With ActiveSheet.Range("B2:10000")
.Formula = "=A2-INT(A2)"
.Copy
Range("A2:A10000").PasteSpecial (xlValues)
.Clear
End With




--
HTH,
Bernie
MS Excel MVP
"Tod" wrote in message
...
I have a column with dates and times. I want to take the
date out. So I'm doing it like this:

For each Cell in ActiveSheet.Range("A2:A10000")
Cell.Value = Cell.Value - Int(Cell.Value)
Next Cell

This works, but it adds minutes to the procedure. Is
there a statement or other that will just make the change
to the entire range at once?

tod





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

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