Consulting

Results 1 to 7 of 7

Thread: Sort/ transfer data

  1. #1
    VBAX Regular
    Joined
    Jan 2017
    Location
    Warsaw
    Posts
    70
    Location

    Sort/ transfer data

    Hey guys!

    I am just trying to structure my data and to collect records, which information is missing, in another table.

    So far, I have copied to tblTwo with the following code, records, or rows, which did not empty the data in column A (empty).

    PHP Code:
        With tblExport.UsedRange
            
    .AutoFilter 1""
            
    With .Offset(10).SpecialCells(12)
                .
    Copy tblTwo.Cells(tblTwo.Cells(Rows.Count2).End(xlUp).Row 11)
                .
    Delete
            End With
            
    .AutoFilter 1
        End With 
    However, I now have to expand the following conditions:

    If column A = "" then cut and paste row after tblTwo.
    If column D = "" then cut and paste row after tblTwo.
    If column E, F, G or O = "" then cut and paste all rows of this class (class oriented to column D) after tblTwo.

    The difficulty is that when columns E, F, G, or O are empty, these rows are transferred to tblTwo, but including the entire class.
    In this case, the class / group is oriented to column D. Note, however, that this group should be located within the group of column C. Thus, there may be the same cells of the group from column D, but these belong to different classes from column C. Correspondingly, the entire class of column D is to be observed or transferred within the class of column c.

    Does anyone have a meaningful approach to me or any suggestions?
    Attached Files Attached Files

  2. #2
    VBAX Expert
    Joined
    Sep 2016
    Posts
    788
    Location
    Option Explicit
    
    
    Sub test2()
        Dim rngS As Range
        Dim rngC As Range
        Dim rngD As Range
        Dim v, i As Long
        
        Set rngS = tblExport.Range("A1").CurrentRegion.Resize(, 17)
        Set rngC = rngS.Resize(2, 1).Offset(rngS.Rows.Count + 2)
        rngC.Cells(2).Formula = "=OR(E2="""",F2="""",G2="""",O2="""")"
        
        Set rngD = rngC.Resize(1, 2).Offset(rngC.Rows.Count + 2)
        rngD.Value = rngS.Range("C1:D1").Value
        
        rngS.AdvancedFilter xlFilterCopy, rngC, rngD, True
        v = rngD.CurrentRegion.Value
        
        rngC.ClearContents
        rngD.CurrentRegion.ClearContents
        
        With tblExport.Range("A1").CurrentRegion.Resize(, 17)
            .AutoFilter 1, ""
            With .Offset(1)
                .Copy tblTwo.Cells(tblTwo.Cells(Rows.Count, 2).End(xlUp).Row + 1, 1)
                .Delete
            End With
            .AutoFilter
        End With
        
        With tblExport.Range("A1").CurrentRegion.Resize(, 17)
            .AutoFilter 4, ""
            With .Offset(1)
                .Copy tblTwo.Cells(tblTwo.Cells(Rows.Count, 2).End(xlUp).Row + 1, 1)
                .Delete
            End With
            .AutoFilter
        End With
        
        For i = 2 To UBound(v)
            With tblExport.Range("A1").CurrentRegion.Resize(, 17)
                .AutoFilter 3, v(i, 1)
                .AutoFilter 4, v(i, 2)
                With .Offset(1)
                    .Copy tblTwo.Cells(tblTwo.Cells(Rows.Count, 2).End(xlUp).Row + 1, 1)
                    .Delete
                End With
                .AutoFilter
            End With
        Next
        
    End Sub

  3. #3
    VBAX Regular
    Joined
    Jan 2017
    Location
    Warsaw
    Posts
    70
    Location
    Thank you for your response and your approach (:I would like to register at the latest Wednesday, if everything has worked

  4. #4
    VBAX Regular
    Joined
    Jan 2017
    Location
    Warsaw
    Posts
    70
    Location
    It's working perfect!
    Many thanks (:
    I get a message saying I want to delete the rows. How can I disable this and declare it with positive?

  5. #5
    VBAX Expert
    Joined
    Sep 2016
    Posts
    788
    Location
    application.displayalerts=false
    &
    application.displayalerts=true

  6. #6
    VBAX Regular
    Joined
    Jan 2017
    Location
    Warsaw
    Posts
    70
    Location
    Many thanks!

  7. #7
    VBAX Expert
    Joined
    Sep 2016
    Posts
    788
    Location
    or

    > .Delete

    .Delete xlShiftUp

Posting Permissions

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