Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

excel vba code to divide coloumns

Status
Not open for further replies.

peace77

Technical User
Jan 3, 2008
24
CA
I need Excel vba code to divide Column G by Column H and store the values in Column I.

The data looks like this

Column g Column h Column i

10,000.00 23
24,750.00 25
10,200.00 26
-3,127.04 28


I am not thorough with VBA and have made an attempt to write this code after gathering pieces from here and there. But this isn’t working at all.


Code:
x = Selection.Rows.count
    Worksheets("Settled Wire").Range("A" & x + 4).Value = "END NOW"
    countx = 1
    count = 0


Do Until Range("A" & countx).Value = "END NOW"

       Range("I" & countx).Formula = "=Range("G" & countx)/Range("H" & countx)"
       countx = countx + 1
    Loop


I would really appreciate if some one can suggest the correction needed or suggest any other alternate code.

Thanks for the help.
 




Hi,

Check out the AutoFill Method. No loop.

Skip,

[glasses]Did you hear what happened when the OO programmer lost his library?...
He's now living in OBJECT poverty![tongue]
 




BTW, your terminology, "excel vba code to divide coloumns" lead me to believe that you wanted to parse text in a column in order to divide it into one or more columns.

Here's tip regarding defining the destination fill range.

[A1].CurrentRegion.Entire Row defines the ROWS for the data range. Columns("I:I") defines the COLUMN for the formula.

Use the Intersect Method to define the exact range to fill.

Skip,

[glasses]Did you hear what happened when the OO programmer lost his library?...
He's now living in OBJECT poverty![tongue]
 
Please excuse me for my terminologies. I am trying to pick the programming lingo.

I do not have a defined range and hence I can not use the Autofill method. The number of rows in coloumn G and H keeps changing and hence i was using the loop to make it dynamic.

I am not sure about the INTERSECT method..will do some research on that to see if I can find the solution. Thanks for the tip.

Peace77
 




[A1].CurrentRegion.Entire Row IS dynamic! That's the POINT!

Skip,

[glasses]Did you hear what happened when the OO programmer lost his library?...
He's now living in OBJECT poverty![tongue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top