ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Divide one range with another (https://www.excelbanter.com/excel-programming/434060-divide-one-range-another.html)

Josip

Divide one range with another
 
Hello,

is there a way in VBA to perform elementwise division on two ranges of
numbers, say A1:B10 and C1:D10? I.e.
A1/C1, A2/C2, ...

Thanks,
J

Mike H

Divide one range with another
 
Josip,

Yes tha's possible but your question isn't very clear. What are the ranges
and how do you want the answers produced to be presented. This divides column
A by column C and prints the answer to the immediate window

On Error Resume Next
For x = 1 To 10
Debug.Print Cells(x, 1) / Cells(x, 3)
Next
End Sub

Mike

"Josip" wrote:

Hello,

is there a way in VBA to perform elementwise division on two ranges of
numbers, say A1:B10 and C1:D10? I.e.
A1/C1, A2/C2, ...

Thanks,
J


Josip

Divide one range with another
 
Thank you,
sorry if I was a bit unclear. So, the problem is that I have two sets
of ranges, e.g.:
1. Columns A and B, rows 1 to 10.
2. Columns C and D, rows 1 to 10.

And I want to store this data in a Range variable for later use. Would
it be possible to use something like this:
"Set myRange = Cells(1, 1).Resize(2, 10) / Cells(3, 1).Resize(2, 10)"

Ok, that does not work, but something like that? Or do I need to use
those fore claues?




On Sep 24, 11:25*am, Mike H wrote:
Josip,

Yes tha's possible but your question isn't very clear. What are the ranges
and how do you want the answers produced to be presented. This divides column
A by column C and prints the answer to the immediate window

On Error Resume Next
For x = 1 To 10
Debug.Print Cells(x, 1) / Cells(x, 3)
Next
End Sub

Mike

"Josip" wrote:
Hello,


is there a way in VBA to perform elementwise division on two ranges of
numbers, say A1:B10 and C1:D10? I.e.
A1/C1, A2/C2, ...


Thanks,
J



Mike H

Divide one range with another
 
Hi,

Try this

For Each c In Range("A1:a10")
c.Offset(, 4).Value = (c + c.Offset(, 1)) / (c.Offset(, 2) + c.Offset(, 3))
Next

Mike

"Josip" wrote:

Thank you,
sorry if I was a bit unclear. So, the problem is that I have two sets
of ranges, e.g.:
1. Columns A and B, rows 1 to 10.
2. Columns C and D, rows 1 to 10.

And I want to store this data in a Range variable for later use. Would
it be possible to use something like this:
"Set myRange = Cells(1, 1).Resize(2, 10) / Cells(3, 1).Resize(2, 10)"

Ok, that does not work, but something like that? Or do I need to use
those fore claues?




On Sep 24, 11:25 am, Mike H wrote:
Josip,

Yes tha's possible but your question isn't very clear. What are the ranges
and how do you want the answers produced to be presented. This divides column
A by column C and prints the answer to the immediate window

On Error Resume Next
For x = 1 To 10
Debug.Print Cells(x, 1) / Cells(x, 3)
Next
End Sub

Mike

"Josip" wrote:
Hello,


is there a way in VBA to perform elementwise division on two ranges of
numbers, say A1:B10 and C1:D10? I.e.
A1/C1, A2/C2, ...


Thanks,
J




Josip

Divide one range with another
 
Thank you very much,

c.Offset(, 4).Value = c / c.Offset(, 2)

worked perfectly for my needs.



On Sep 24, 12:49*pm, Mike H wrote:
Hi,

Try this

For Each c In Range("A1:a10")
c.Offset(, 4).Value = (c + c.Offset(, 1)) / (c.Offset(, 2) + c.Offset(, 3))
Next

Mike

"Josip" wrote:
Thank you,
sorry if I was a bit unclear. So, the problem is that I have two sets
of ranges, e.g.:
1. Columns A and B, rows 1 to 10.
2. Columns C and D, rows 1 to 10.


And I want to store this data in a Range variable for later use. Would
it be possible to use something like this:
"Set myRange = Cells(1, 1).Resize(2, 10) / Cells(3, 1).Resize(2, 10)"


Ok, that does not work, but something like that? Or do I need to use
those fore claues?


On Sep 24, 11:25 am, Mike H wrote:
Josip,


Yes tha's possible but your question isn't very clear. What are the ranges
and how do you want the answers produced to be presented. This divides column
A by column C and prints the answer to the immediate window


On Error Resume Next
For x = 1 To 10
Debug.Print Cells(x, 1) / Cells(x, 3)
Next
End Sub


Mike


"Josip" wrote:
Hello,


is there a way in VBA to perform elementwise division on two ranges of
numbers, say A1:B10 and C1:D10? I.e.
A1/C1, A2/C2, ...


Thanks,
J



Mike H

Divide one range with another
 
Glad i could help and thanks for the feedback

"Josip" wrote:

Thank you very much,

c.Offset(, 4).Value = c / c.Offset(, 2)

worked perfectly for my needs.



On Sep 24, 12:49 pm, Mike H wrote:
Hi,

Try this

For Each c In Range("A1:a10")
c.Offset(, 4).Value = (c + c.Offset(, 1)) / (c.Offset(, 2) + c.Offset(, 3))
Next

Mike

"Josip" wrote:
Thank you,
sorry if I was a bit unclear. So, the problem is that I have two sets
of ranges, e.g.:
1. Columns A and B, rows 1 to 10.
2. Columns C and D, rows 1 to 10.


And I want to store this data in a Range variable for later use. Would
it be possible to use something like this:
"Set myRange = Cells(1, 1).Resize(2, 10) / Cells(3, 1).Resize(2, 10)"


Ok, that does not work, but something like that? Or do I need to use
those fore claues?


On Sep 24, 11:25 am, Mike H wrote:
Josip,


Yes tha's possible but your question isn't very clear. What are the ranges
and how do you want the answers produced to be presented. This divides column
A by column C and prints the answer to the immediate window


On Error Resume Next
For x = 1 To 10
Debug.Print Cells(x, 1) / Cells(x, 3)
Next
End Sub


Mike


"Josip" wrote:
Hello,


is there a way in VBA to perform elementwise division on two ranges of
numbers, say A1:B10 and C1:D10? I.e.
A1/C1, A2/C2, ...


Thanks,
J




Josip

Divide one range with another
 
Actuall, one more thing. Is it possible to store these results in a
Range variable and not justi in cells determined by the offset(,4)?



On Sep 24, 1:04*pm, Josip wrote:
Thank you very much,

c.Offset(, 4).Value = c / c.Offset(, 2)

worked perfectly for my needs.

On Sep 24, 12:49*pm, Mike H wrote:

Hi,


Try this


For Each c In Range("A1:a10")
c.Offset(, 4).Value = (c + c.Offset(, 1)) / (c.Offset(, 2) + c.Offset(, 3))
Next


Mike


"Josip" wrote:
Thank you,
sorry if I was a bit unclear. So, the problem is that I have two sets
of ranges, e.g.:
1. Columns A and B, rows 1 to 10.
2. Columns C and D, rows 1 to 10.


And I want to store this data in a Range variable for later use. Would
it be possible to use something like this:
"Set myRange = Cells(1, 1).Resize(2, 10) / Cells(3, 1).Resize(2, 10)"


Ok, that does not work, but something like that? Or do I need to use
those fore claues?


On Sep 24, 11:25 am, Mike H wrote:
Josip,


Yes tha's possible but your question isn't very clear. What are the ranges
and how do you want the answers produced to be presented. This divides column
A by column C and prints the answer to the immediate window


On Error Resume Next
For x = 1 To 10
Debug.Print Cells(x, 1) / Cells(x, 3)
Next
End Sub


Mike


"Josip" wrote:
Hello,


is there a way in VBA to perform elementwise division on two ranges of
numbers, say A1:B10 and C1:D10? I.e.
A1/C1, A2/C2, ...


Thanks,
J



Peter T

Divide one range with another
 
Unless you need the result in VBA for other reasons

=SUM(A1:B10/C1:D10)

Array enter with Ctrl-Shift-Enter

Regards,
Peter T

"Josip" wrote in message
...
Hello,

is there a way in VBA to perform elementwise division on two ranges of
numbers, say A1:B10 and C1:D10? I.e.
A1/C1, A2/C2, ...

Thanks,
J




Mike H

Divide one range with another
 
Hi,

You can put them in an array. The message box bit at the end is just to
demonstrate it worked.

Sub Populate_an_Array()
x = 1
Dim vaArray() As Variant
lastrow = Cells(Cells.Rows.Count, "A").End(xlUp).Row
ReDim vaArray(1 To lastrow)
For Each c In Range("A1:A" & lastrow)
vaArray(x) = c / c.Offset(, 2)
x = x + 1
Next

For x = 1 To 10
MsgBox vaArray(x)
Next
End Sub

Mike

"Josip" wrote:

Actuall, one more thing. Is it possible to store these results in a
Range variable and not justi in cells determined by the offset(,4)?



On Sep 24, 1:04 pm, Josip wrote:
Thank you very much,

c.Offset(, 4).Value = c / c.Offset(, 2)

worked perfectly for my needs.

On Sep 24, 12:49 pm, Mike H wrote:

Hi,


Try this


For Each c In Range("A1:a10")
c.Offset(, 4).Value = (c + c.Offset(, 1)) / (c.Offset(, 2) + c.Offset(, 3))
Next


Mike


"Josip" wrote:
Thank you,
sorry if I was a bit unclear. So, the problem is that I have two sets
of ranges, e.g.:
1. Columns A and B, rows 1 to 10.
2. Columns C and D, rows 1 to 10.


And I want to store this data in a Range variable for later use. Would
it be possible to use something like this:
"Set myRange = Cells(1, 1).Resize(2, 10) / Cells(3, 1).Resize(2, 10)"


Ok, that does not work, but something like that? Or do I need to use
those fore claues?


On Sep 24, 11:25 am, Mike H wrote:
Josip,


Yes tha's possible but your question isn't very clear. What are the ranges
and how do you want the answers produced to be presented. This divides column
A by column C and prints the answer to the immediate window


On Error Resume Next
For x = 1 To 10
Debug.Print Cells(x, 1) / Cells(x, 3)
Next
End Sub


Mike


"Josip" wrote:
Hello,


is there a way in VBA to perform elementwise division on two ranges of
numbers, say A1:B10 and C1:D10? I.e.
A1/C1, A2/C2, ...


Thanks,
J





All times are GMT +1. The time now is 10:33 PM.

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