Division

SGlobal

New Member
Joined
May 10, 2011
Messages
7
I need to divide the values of each cell in column A with the corresponding cell in Column b with VBA. how can I do that?

so say I have these values
A B C
1 3 1/3
2 2 2/2
3 1 3/1

Column C should = 1/3 C1, 2/2 for C2, and so on and so forth

I have a full list of these how can I do that with a macro?
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Do you just want it to say 1/3 or do you want it to actually divide it out?
 
Upvote 0
SbGlobal,
Sorry about my first reply, in the middle of writing out the macro, I pressed the wrong key and kicked myself into another screen.

It looks like you have someone helping you already. Best of luck.
 
Upvote 0
If it is to display the text:

Code:
Sub test()
Range("C:C").NumberFormat = "General"
With Range("C1:C" & Range("A" & Rows.Count).End(xlUp).Row)
    .Formula = "=A1&""/""&B1"
    .NumberFormat = "@"
    .Value = .Value
End With
End Sub

If it's to divide it out:

Code:
Sub test()
Range("C:C").NumberFormat = "General"
With Range("C1:C" & Range("A" & Rows.Count).End(xlUp).Row)
    .Formula = "=A1/B1"
    .Value = .Value
End With
End Sub
 
Upvote 0
You could both return the value and show the fraction

Code:
Dim oneCell as Range

For each oneCell in Range("A1:A10")
    With oneCell
        .Offset(0,2).Value = .Value / .Offset(0,1).Value
        .Offset(0,2).NumberFormat = Chr(34) & CStr(.Value) & "/" & CStr(.Offset(0,1).Value) & Chr(34)
    End With
Next oneCell
 
Upvote 0
<HR style="BACKGROUND-COLOR: #ffffff; COLOR: #ffffff" SIZE=1>
You could both return the value and show the fraction

Depending on the length of the actual list you could run out of available number formats.
 
Upvote 0
<HR style="BACKGROUND-COLOR: #ffffff; COLOR: #ffffff" SIZE=1>

Depending on the length of the actual list you could run out of available number formats.

True. Hmm...other than looping through cells, is there some way to count the number of number formats in use by a particular workbook? I can't think of one.
 
Upvote 0

Forum statistics

Threads
1,224,597
Messages
6,179,812
Members
452,945
Latest member
Bib195

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top