Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old August 11th, 2011, 01:57 PM
Registered User
Join Date: Jun 2011
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default Loop until cell is within 1 of another cell

I have a do loop that makes an adjustment from one cell to another cell.
This is to avoid a circular refererence. Sometimes it will not stop looping because the two cells are off by one and then when one goes up the other goes down, etc. Is there a way to make it loop until cell C14 is plus 1 or minus 1 of E14. In other words, within one whole number.
Sub Taxes_Adjust()


    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
Loop Until Range("C14").Value = Range("E14").Value
End Sub
Old August 16th, 2011, 06:08 AM
Friend of Wrox
Join Date: Sep 2005
Posts: 812
Thanks: 1
Thanked 53 Times in 49 Posts


Can you try

abs(Range("C14").Value - Range("E14").Value) = 1
C# Code Snippets (http://www.dotnetdud.blogspot.com)

VBA Tips & Tricks (http://www.vbadud.blogspot.com)
Old August 16th, 2011, 12:03 PM
Registered User
Join Date: Jun 2011
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Smile It worked with a small change.

Thank you! I couldn't find anything in Excel 2003 VBA about that function.

Loop Until Abs(Range("Adjusted").Value - Range("Tax").Value) <= 0.99
I had to change it to less than or equal to because it was looking for an exact number. I also named my cell references to simplify things.

Similar Threads
Thread Thread Starter Forum Replies Last Post
cell is empty while using For Each cell In Range jase2007 Excel VBA 4 April 5th, 2012 10:20 PM
Separating a CSV cell into 1 value per cell bigtonyicu Excel VBA 2 March 14th, 2008 12:28 PM
I need to refer a cell within a cell like =RC[ RC2 chakravarthi_os Excel VBA 1 September 24th, 2006 08:19 AM
if the cell content is a part of another cell cont sriramus Excel VBA 1 November 15th, 2005 10:20 AM
Lose cell Text when editing cell in VSFlexGrid 6 bobcratchet VB How-To 0 July 30th, 2004 09:32 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.