Re: Is A Do Loop Efficient
billyj
Code
Sub AVAILABLEBILLETS()
Dim xlCalc As XlCalculation
Dim sh1 As Worksheet, sh2 As Worksheet, sh3 As Worksheet
xlCalc = Application.Calculation
Application.Calculation = xlCalculationManual
On Error GoTo CalcBack
Application.ScreenUpdating = False
Dim j As Long, i As Long, fillcell As Long
Set sh1 = Sheets("AVAILABLE BILLETS")
Set sh2 = Sheets("DECK AVAILABLE BILLETS")
Set sh3 = Sheets("OPS AVAILABLE BILLETS")
sh1.Rows("1:1000").Delete Shift:=xlUp ' delete old data
i = 3
With sh2
.Range("A1:G2").Copy sh1.Range("A1") ' copy header info
Do While .Range("F" & i).Value <> ""
Select Case True
Case .Range("F" & i) = "ASAP", .Range("F" & i) = "RESEARCH", .Range("F" & i) = "Select me"
.Range("A" & i & ":E" & i).Copy sh1.Range("A" & i & ":E" & i)
Case Else
' do nothing
End Select
i = i + 1
Loop
End With
With sh3
.Range("A1:G2").Copy sh1.Range("A" & i + 1) 'copy header info
j = 3
Do While .Range("F" & j).Value <> ""
Select Case True
Case .Range("F" & j) = "RESEARCH", .Range("F" & j) = "ASAP", .Range("F" & j) = "Select me"
fillcell = i + j
.Range("A" & j & ":E" & j).Copy sh1.Range("A" & fillcell & ":E" & fillcell)
Case Else
' do nothing
End Select
j = j + 1
Loop
End With
'YOUR CODE
Application.Calculation = xlCalc
Exit Sub
CalcBack:
Application.Calculation = xlCalc
Application.ScreenUpdating = True
End Sub
Display More
This code works poerfectly now. The use of True in the Select case staement is to achieve the so call C-type Shortcircuit ( this boost performances )); Excel up to now - maybe the 2007 has chaged - proofs all conditions in a if...then using select case true ( for OR ) or false ( for and ) allows you to break your proofing as soon one TRUE condition is met ( in case of OR ) or a FALSE one ( in case of AND ). BE CAREFULL using it
see: http://www.ozgrid.com/forum/showthread.php?t=41814
HTH
Filippo