[VBA] Do Until range ("W1").value >= TGT (0.2)

RockandGrohl

Well-known Member
Joined
Aug 1, 2018
Messages
810
Office Version
  1. 365
Platform
  1. Windows
Hi all,

Have a value in W1 that started at 0.13 (or 13%)

I'm trying to execute a loop up until the point where the value in W1 exceeds the TGT, which is set as "0.2"

At the bottom of the loop, the value in W1 updates to be higher or lower.

Currently, starting at 0.13 and aiming to be equal or higher than 0.2, my loop is at 0.34 and still going.

Do I need to declare this as a variable, a variant or what?

Code:
EUAllocation.EUTarget.Caption = Format(EUValue / 100, "0%")

~~~~~~~~ NEW SUB ~~~~~~~~~~

Code:
Private Sub EUStart_Click()


Set ads = Worksheets("Adselect")
Set atm = Worksheets("ATM")


Application.ScreenUpdating = False


TGT = Format(EUAllocation.EUTarget.Caption, "0.0")


[Lots of irrelevant code]

Do Until Range("W1").Value >= TGT
Range("A3").Activate
Range("W1").FormulaR1C1 = "=COUNTIF(C7,""*EU*"")/COUNTIFS(C6,""Just Go"",C11,""Y"")"
Range("W1").Value = Range("W1").Value
Loop


Thanks!
 
You need to use

Code:
Dim TGT As Double

or it wont work properly. Take this example:

Code:
Dim TGT As String
Dim x As Double

TGT = "10"
x = 1

Do Until Range("W1").Value >= TGT
    Range("W1") = x
    x = x + 1
Loop

When you run that check out the value of W1. Then run this:

Code:
Dim TGT As Double
Dim x As Double

TGT = "10"
x = 1

Do Until Range("W1").Value >= TGT
    Range("W1") = x
    x = x + 1
Loop
 
Last edited:
Upvote 0

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
OK Rock, we all make mistakes (and I make more than most). It boils down to what Steve says. Declare tgt as double, or Long and that should fix it.
 
Upvote 0
You need to use

Code:
Dim TGT As Double

or it wont work properly. Take this example:

Code:
Dim TGT As String
Dim x As Double

TGT = "10"
x = 1

Do Until Range("W1").Value >= TGT
    Range("W1") = x
    x = x + 1
Loop

When you run that check out the value of W1. Then run this:

Code:
Dim TGT As Double
Dim x As Double

TGT = "10"
x = 1

Do Until Range("W1").Value >= TGT
    Range("W1") = x
    x = x + 1
Loop

Thanks, that worked perfectly and now my code looks a little cleaner :))) Sorry about the mess earlier, that'll teach for me quickly trying to write up my issue!
 
Upvote 0
OK Rock, we all make mistakes (and I make more than most). It boils down to what Steve says. Declare tgt as double, or Long and that should fix it.

Yeah thanks for bearing with me, I totally rushed the explanation.

It's really fun now that it's working so cleanly, I'm just swapping templates around with a nice userform, beats doing it by hand, wheeee!!
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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