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 June 7th, 2004, 06:37 AM
Authorized User
 
Join Date: May 2004
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default Do.....Loop until IsEmpty(....)

I have a workbook that contains 5 worksheets, i want to loop through only three sheets that contains my data until the match is found(see the macro), then stop the looping and proceed the rest of the macro.......

here is the full macro with my small try to loop through two sheets(4 and 2)
i tried it onc using Do....loop and another time using only if........but!!!!!!!

would any one pls help.............

I placed this macro in the stock sheet

Private Sub Worksheet_Change(ByVal Target As Range)
Dim OrdVal As Long
Dim strOrd As String
Dim lrow As Long
Dim rngStock As Range
Dim myCheck As Integer

On Error GoTo err
If Application.Intersect(Target, Range("B2:B10")) Is Nothing Then
    'Exit Sub
Else
    OrdVal = Target.Value
    strOrd = Target.Offset(0, -1).Value

    myCheck = MsgBox("" & OrdVal & " Units of " & strOrd & " were ordered", vbYesNo)
    If myCheck = vbNo Then
    Exit Sub
    End If

    Do Until IsEmpty(strOrd)
    If lrow = Application.Match(strOrd, Sheet4.Range("A2:A10"), 0) Then
      Set rngStock = Sheets("Stock").Range("A1").Offset(lrow, 1)
    rngStock.Value = rngStock.Value - OrdVal
    Else
    lrow = Application.Match(strOrd, Sheet2.Range("A2:A10"), 0)
    Set rngStock = Sheets("Stock").Range("A1").Offset(lrow, 1)
    rngStock.Value = rngStock.Value - OrdVal
    End If
    Loop

End If
Set rngStock = Nothing
err: Exit Sub
End Sub

yours
hesham






Similar Threads
Thread Thread Starter Forum Replies Last Post
Do Until IsEmpty function mesinbasuh Excel VBA 0 September 18th, 2006 09:43 PM
Do Until loop with IF crmpicco Classic ASP Databases 2 June 15th, 2005 05:35 PM
For....Loop kliu9 Excel VBA 5 February 10th, 2005 06:43 AM
Do Loop junemo Beginning PHP 8 July 28th, 2004 02:58 AM
nested while loop doesn't loop hosefo81 PHP Databases 5 November 12th, 2003 08:46 AM





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