Results 1 to 8 of 8

Edit a small code to remove error

Threaded View

moonbreakker Edit a small code to remove... 07-29-2015, 05:38 AM
Parth007 Re: Edit a small code to... 07-29-2015, 06:49 AM
moonbreakker Re: Edit a small code to... 07-29-2015, 07:03 AM
Parth007 Re: Edit a small code to... 07-29-2015, 07:42 AM
moonbreakker Re: Edit a small code to... 07-29-2015, 07:47 AM
Parth007 Re: Edit a small code to... 07-29-2015, 07:53 AM
moonbreakker Re: Edit a small code to... 07-29-2015, 07:56 AM
Parth007 Re: Edit a small code to... 07-29-2015, 08:09 AM
  1. #1
    Forum Contributor
    Join Date
    02-23-2012
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    133

    Edit a small code to remove error

    Hello,

    Credit for the codes to Skywriter.

    In attached sheet, macro2 (StatusMove) only has the issue. It runs fine IF and ONLY if all three entries (Delivered, Hold, Rejected) are present in column H. If any of the three is missing it gives 1004 with cells not found error.

    I want it to run with any of the entries. And if H is blank, it can give message like Status is empty or something.

    Any help will be greatly appreciated.

    Option Explicit
    
    Sub PopulateSheet2()
    Dim ws1 As Worksheet, ws2 As Worksheet, arrModels, j As Long, c As Long, x As Long, suCount As Long, aCount As Long
    Dim myAreas As Areas, y As Long
    Set ws1 = Worksheets("Sheet1"): Set ws2 = Worksheets("Sheet2")
    
    Application.ScreenUpdating = False
    
    ws2.Range("A1").CurrentRegion.Offset(1).ClearContents
    
    With ws2.Range("L1").CurrentRegion
        arrModels = .Offset(1).Resize(.Rows.Count - 1, .Columns.Count)
    End With
    
    With ws1.Range("A1").CurrentRegion
    .Sort Key1:=.Range("B1"), Order1:=xlAscending, Header:=xlYes
        For j = LBound(arrModels) To UBound(arrModels)
            .AutoFilter 6, Criteria1:=arrModels(j, 1)
                c = .Columns(1).SpecialCells(xlCellTypeVisible).Cells.Count - 1
                x = arrModels(j, 2) + arrModels(j, 3)
                suCount = WorksheetFunction.Min(c, x)
                Set myAreas = .Offset(1).Resize(.Rows.Count - 1, 6).SpecialCells(xlCellTypeVisible).Areas
               aCount = myAreas.Count
     
                For c = 1 To myAreas.Count
                    If suCount = 0 Then GoTo 1
                    If myAreas(c).Rows.Count <= suCount Then
                        myAreas(c).Rows.Copy ws2.Cells(ws2.Rows.Count, "A").End(xlUp).Offset(1)
                        suCount = suCount - myAreas(c).Rows.Count
                    Else
                        For x = 1 To suCount
                            myAreas(c).Rows(x).Copy ws2.Cells(ws2.Rows.Count, "A").End(xlUp).Offset(1)
                            suCount = suCount - 1
                        Next x
                    End If
                Next c
             
    1          .AutoFilter
    
        Next j
    End With
        With ws2
        
            x = .Cells(Rows.Count, "F").End(xlUp).Row
        
                If x < 2 Then Exit Sub
                y = 2
         For j = LBound(arrModels) To UBound(arrModels)
            If arrModels(j, 2) > 0 Then
                For c = 1 To arrModels(j, 2)
                     If arrModels(j, 1) = .Cells(y, 6) And y < x + 1 Then
                         .Cells(y, 7) = "READY FOR DELIVERY"
                        y = y + 1
                    Else
                        Exit For
                     End If
                Next c
            End If
            
            If arrModels(j, 3) > 0 Then
                For c = 1 To arrModels(j, 3)
                    If arrModels(j, 1) = .Cells(y, 6) And y < x + 1 Then
                        .Cells(y, 7) = "UP-COMING"
                         y = y + 1
                    Else
                        Exit For
                    End If
                Next c
            End If
           
         Next j
        
    End With
    
    Application.ScreenUpdating = True
    
    End Sub
    
     Sub StatusMove()
     
     Dim ws1 As Worksheet, ws2 As Worksheet
     Dim arrFilterCriteria, r As Range, j As Long, rngFound As Range, rngData As Range
     Set ws1 = Worksheets("Sheet1"): Set ws2 = Worksheets("Sheet2")
      
      arrFilterCriteria = Array("DELIVERED", "REJECTED", "HOLD")
      
     Application.ScreenUpdating = False
     
     With ws2.Range("A1").CurrentRegion
     Set rngData = .Offset(1).Resize(.Rows.Count - 1, Columns.Count)
     
           For j = LBound(arrFilterCriteria) To UBound(arrFilterCriteria)
                .AutoFilter 8, Criteria1:=arrFilterCriteria(j)
                        For Each r In rngData.Columns(1).SpecialCells(xlCellTypeVisible)
                    
                        If r.Value <> Empty Then
                            With ws1.Columns(1)
                                Set rngFound = .Find(r.Value)
                                    If Not rngFound Is Nothing Then
                                        Range(rngFound, rngFound.Offset(, 5)).Delete Shift:=xlUp
                                    End If
                            End With
                        End If
                    Next r
                                    
                   .Offset(1).Copy Worksheets(arrFilterCriteria(j)).Cells(Worksheets(arrFilterCriteria(j)).Rows.Count, "A").End(xlUp).Offset(1)
                   .Offset(1).ClearContents
                   
    1                    .AutoFilter
            Next j
                 .Offset(1).Sort Key1:=.Range("A2")
     End With
    
     Application.ScreenUpdating = True
    
     End Sub
    Thank you.
    Attached Files Attached Files

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Blank cell gives error 13 (Mismatch) in loop - edit code to accommodate for blanks
    By onmyway in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 04-17-2015, 07:35 AM
  2. [SOLVED] Macro small edit
    By makinmomb in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 05-08-2014, 06:10 AM
  3. [SOLVED] Remove the error and clean my code to send mail automatically from excel
    By mukeshbaviskar in forum Outlook Programming / VBA / Macros
    Replies: 9
    Last Post: 08-22-2013, 09:26 AM
  4. Error when executing VBA code to remove all formulas from Workbook
    By brharrii in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 06-17-2013, 05:17 PM
  5. Edit code to loop error msgbox and inputbox until valid date is entered by user.
    By rocksan in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-11-2012, 10:07 PM
  6. [SOLVED] Coyping results in Run-TIme Error 424, Need help to edit code
    By rocksan in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-02-2012, 12:08 AM
  7. Getting Error 400 with following code. How do I remove it?
    By paulabrozek in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-05-2008, 12:28 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1