Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default 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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default 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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default 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


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default 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



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default 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




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default 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



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default 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


  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default 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



  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default 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



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Divide by the minimum non-zero number in a range of cells Opus Excel Worksheet Functions 22 June 14th 09 08:27 PM
Divide a range of cells by a number Kate Excel Discussion (Misc queries) 3 May 3rd 08 06:36 PM
divide all numbers in range by a fixed number dhig3903 Excel Discussion (Misc queries) 2 August 9th 06 08:04 AM
Divide one row over other row I dont wont to divide one number Rick Excel Discussion (Misc queries) 0 March 4th 05 07:13 PM
Divide Expression stops in Macro when Can't divide JUAN Excel Programming 6 May 6th 04 07:05 AM


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

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"