ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Calculations in VBA (https://www.excelbanter.com/excel-programming/340020-calculations-vba.html)

Murtaza

Calculations in VBA
 
I have a Named Range called "Data_Cells"
[='Sheet1'!$F$20:$L$31,'Sheet1'!$N$20:$O$31,'Sheet1 '!$O$42:$O$44)]

Now I wish to divide each cell in "Data_Cells" with the value in "P15"
using VBA like...

For Each cell in "Data_Cells"
Data_Cells.value/P15
Exit for

Please help







Gary Keramidas[_2_]

Calculations in VBA
 
see if this will work for you


Option Explicit
Dim r1 As Range
Dim r2 As Range
Dim cell As Range

Sub test2()
Set r1 = Range("data_cells")
Set r2 = Range("p15")
r1.Select
For Each cell In Range("data_cells")
cell.Value = cell.Value / r2
Next

End Sub

--


Gary


"Murtaza" <NoEmail@NoEmail wrote in message
...
I have a Named Range called "Data_Cells"
[='Sheet1'!$F$20:$L$31,'Sheet1'!$N$20:$O$31,'Sheet1 '!$O$42:$O$44)]

Now I wish to divide each cell in "Data_Cells" with the value in "P15"
using VBA like...

For Each cell in "Data_Cells"
Data_Cells.value/P15
Exit for

Please help









Harald Staff

Calculations in VBA
 
Sub test()
Dim cel As Range
Dim P As Double
P = Sheets(1).Range("P15").Value
If P = 0 Then Exit Sub
For Each cel In Range("Data_cells")
cel.Value = cel.Value / P
Next
End Sub

HTH. Best wishes Harald

"Murtaza" <NoEmail@NoEmail skrev i melding
...
I have a Named Range called "Data_Cells"
[='Sheet1'!$F$20:$L$31,'Sheet1'!$N$20:$O$31,'Sheet1 '!$O$42:$O$44)]

Now I wish to divide each cell in "Data_Cells" with the value in "P15"
using VBA like...

For Each cell in "Data_Cells"
Data_Cells.value/P15
Exit for

Please help










All times are GMT +1. The time now is 04:07 PM.

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