View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Geoff_L[_2_] Geoff_L[_2_] is offline
external usenet poster
 
Posts: 13
Default Loop Until non-incrementing cell condition met.

It is not very clear why the value of GJ1 changes when you are recoopying the
same thing over and over again. However, assuming that the condition is met
eventually there are two things that could be awry is your posted code is a
true replication of the VBA.
1. Do Until GJ1 = 1 - VBA may be seeing GJ1 and a variable that is never
assigned a value and therefore the condition is never met. (This assumes
that you are not using Option Explicit). Try being a bit more specific with
Range("GJ1")
2. Are you sure that the copying is returning the NUMBER 1 and not the
STRING "1"? It may be that you are looking for one and returning the other.

If this is helpful, please click Yes.

"GBExcel via OfficeKB.com" wrote:

Hi,

I am a VBA dummy. I am stuck on the following:

I have a cell GJ1 that will either have a 1 or a 0 value. My routine needs to
loop until GJ1 changes from 0 to 1. The solutions that I have seen on the
Internet use counters to count loops until a condition is met. In my case,
counters or incrementing is not applicable since the condition that
determines if GJ1 is 1 is not based on counters or incrementing but on user
input. The example below is what I am trying. I can get the loop to work,
but then it just keeps looping infinitely.

Sub PasteValuesTill()

' The code below must loop until cell GJ1=1. GJ1 can only have values of 0 or
1.
'
Sheets("ThisSheet").Select
Range("E5:G5").Select
Selection.Copy
Range("F2:G2").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
Do Until GJ1 = 1
Loop

End Sub

--
Message posted via http://www.officekb.com

.