Sub roundvalues() Dim c As Range For Each c In Range("a2:z22").SpecialCells(xlConstants, xlNumbers) c.Value = Application.Round(c, 2)
‘OR vba round which may round down instead of rounding OFF ‘ c = Round(c, 2) Next c End Sub Don Guillett Microsoft MVP Excel SalesAid Software dguille...@gmail.com From: tangledweb Sent: Sunday, April 08, 2012 5:42 PM To: excel-macros@googlegroups.com Subject: $$Excel-Macros$$ Could this loop be replaced by some range method? I am trying to get more used to using ranges instead of addressing individual cells by indexes. The loop below is rounding off the entries in all the columns where BarOpen for example is just the column index in the sheet. Is there a way to do this more efficiently by using the used range portion of each column? In this case all the columns are the same length. ' Round off the raw data values With Sheets(RawData) For index = startrawdata To stoprawdata Cells(index, BarOpen).Value = WorksheetFunction.Round(.Cells(index, BarOpen).Value, 2) Cells(index, BarHigh).Value = WorksheetFunction.Round(.Cells(index, BarHigh).Value, 2) Cells(index, BarLow).Value = WorksheetFunction.Round(.Cells(index, BarLow).Value, 2) Cells(index, BarClose).Value = WorksheetFunction.Round(.Cells(index, BarClose).Value, 2) Cells(index, StopCol).Value = WorksheetFunction.Round(.Cells(index, StopCol).Value, 2) Next index End With -- FORUM RULES (986+ members already BANNED for violation) 1) Use concise, accurate thread titles. Poor thread titles, like Please Help, Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will not get quick attention or may not be answered. 2) Don't post a question in the thread of another member. 3) Don't post questions regarding breaking or bypassing any security measure. 4) Acknowledge the responses you receive, good or bad. 5) Cross-promotion of, or links to, forums competitive to this forum in signatures are prohibited. NOTE : Don't ever post personal or confidential data in a workbook. Forum owners and members are not responsible for any loss. ------------------------------------------------------------------------------------------------------ To post to this group, send email to excel-macros@googlegroups.com -- FORUM RULES (986+ members already BANNED for violation) 1) Use concise, accurate thread titles. Poor thread titles, like Please Help, Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will not get quick attention or may not be answered. 2) Don't post a question in the thread of another member. 3) Don't post questions regarding breaking or bypassing any security measure. 4) Acknowledge the responses you receive, good or bad. 5) Cross-promotion of, or links to, forums competitive to this forum in signatures are prohibited. NOTE : Don't ever post personal or confidential data in a workbook. Forum owners and members are not responsible for any loss. ------------------------------------------------------------------------------------------------------ To post to this group, send email to excel-macros@googlegroups.com