• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Loop of +1 until condition match

Khalid NGO

Excel Ninja
Hello everyone…

Once again need your help.
I am working on a sheet where I need to make a loop of +1 for column B values, until Column D values match with column E values.

Current loop is working fine but it runs after one by one row.

I need my all loops runs at the same time, not one by one:
is there any way ?

Sharing herewith a sample of my sheet.
 

Attachments

Excel VBA is not-multitask enabled, some functions make use of multiple processors, but as a user you can't

None of the rows are dependent on other rows
So Whats wrong with doing them sequentially?
 
Excel VBA is not-multitask enabled, some functions make use of multiple processors, but as a user you can't

Oh... i didn't knew that.

[quote="None of the rows are dependent on other rows
So Whats wrong with doing them sequentially?[/quote]

Nothing is wrong Sir just:
1) if all loops runs at same time, result will be available much earlier.

2) just for good look.
 
I had another thought

Try This:

Code:
Sub Loop_NewAll()
' Loops until a condition is meet.
Dim A As Long, B As Long, C As Long, D As Long
Dim CountA As Integer, CountB As Integer, CountC As Integer, CountD As Integer

CountA = 0: CountB = 0: CountC = 0: CountD = 0
A = 1: B = 1: C = 1: D = 1

Do

Range("B2").Value = A
If CountA < 1 And Range("D2").Value < Range("E2").Value Then
  A = A + 1
Else
  CountA = CountA + 1
End If

Range("B3").Value = B
If CountB < 1 And Range("D3").Value < Range("E3").Value Then
  B = B + 1
Else
  CountB = CountB + 1
End If

Range("B4").Value = C
If CountC < 1 And Range("D4").Value < Range("E4").Value Then
  C = C + 1
Else
  CountC = CountC + 1
End If

Range("B5").Value = D
If CountD < 1 And Range("D5").Value < Range("E5").Value Then
  D = D + 1
Else
  CountD = CountD + 1
End If


Loop Until CountA > 0 And CountB > 0 And CountC > 0 And CountD > 0

Application.GoTo Sheet1.Range("A1"), True

End Sub
 
Here 'tis

Code:
Sub SuperFast_Solver()
  
Range("D2").GoalSeek Goal:=[E2], ChangingCell:=Range("B2")
Range("D3").GoalSeek Goal:=[E3], ChangingCell:=Range("B3")
Range("D4").GoalSeek Goal:=[E4], ChangingCell:=Range("B4")
Range("D5").GoalSeek Goal:=[E5], ChangingCell:=Range("B5")

End Sub

ps: Don't Blink !
 
I had another thought

Try This:

Code:
Sub Loop_NewAll()
' Loops until a condition is meet.
Dim A As Long, B As Long, C As Long, D As Long
Dim CountA As Integer, CountB As Integer, CountC As Integer, CountD As Integer

CountA = 0: CountB = 0: CountC = 0: CountD = 0
A = 1: B = 1: C = 1: D = 1

Do

Range("B2").Value = A
If CountA < 1 And Range("D2").Value < Range("E2").Value Then
  A = A + 1
Else
  CountA = CountA + 1
End If

Range("B3").Value = B
If CountB < 1 And Range("D3").Value < Range("E3").Value Then
  B = B + 1
Else
  CountB = CountB + 1
End If

Range("B4").Value = C
If CountC < 1 And Range("D4").Value < Range("E4").Value Then
  C = C + 1
Else
  CountC = CountC + 1
End If

Range("B5").Value = D
If CountD < 1 And Range("D5").Value < Range("E5").Value Then
  D = D + 1
Else
  CountD = CountD + 1
End If


Loop Until CountA > 0 And CountB > 0 And CountC > 0 And CountD > 0

Application.GoTo Sheet1.Range("A1"), True

End Sub

Wow...
Excellent.

Exactly what i was after.
 
Here 'tis

Code:
Sub SuperFast_Solver()
 
Range("D2").GoalSeek Goal:=[E2], ChangingCell:=Range("B2")
Range("D3").GoalSeek Goal:=[E3], ChangingCell:=Range("B3")
Range("D4").GoalSeek Goal:=[E4], ChangingCell:=Range("B4")
Range("D5").GoalSeek Goal:=[E5], ChangingCell:=Range("B5")

End Sub

ps: Don't Blink !

Brilliant Sir...
Extremely super fast.

Many thanks Sir Hui.
 
Back
Top