+ Reply to Thread
Results 1 to 4 of 4

Copying/pasting data & delete row up according to criteria

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    08-23-2011
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    404

    Copying/pasting data & delete row up according to criteria

    Hi all,

    I have a macro which executes various subs in order. I'm having trouble with one part of it. Essentially I need some code which produces what is shown in the example worksheet.

    Any ideas?
    Attached Files Attached Files
    Last edited by D_N_L; 03-07-2012 at 06:44 AM.

  2. #2
    Forum Contributor
    Join Date
    02-07-2012
    Location
    MIA
    MS-Off Ver
    Excel 2007, 2010
    Posts
    429

    Re: Copying/pasting data & delete row up according to criteria

    So what you want is to delete the "#¡REF!"?

  3. #3
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Copying/pasting data & delete row up according to criteria

    Try this code in a blank module -
    Option Explicit
    Dim lrow As Long
    Dim lrow1 As Long
    Dim i As Long
    
    Sub clear_data()
    
    With Worksheets("DataPrep")
    lrow = .Range("A" & .Rows.Count).End(xlUp).Row
    lrow1 = .Range("B" & .Rows.Count).End(xlUp).Row
    
    If lrow1 > lrow Then
        lrow = lrow1
    End If
    
    For i = 2 To lrow
        If Application.IsError(.Range("A" & i).Value) = True And Application.IsError(.Range("B" & i).Value) = False Then
            .Range("A" & i).Value = ""
        ElseIf Application.IsError(.Range("A" & i).Value) = False And Application.IsError(.Range("B" & i).Value) = True Then
            .Range("B" & i).Value = ""
        ElseIf Application.IsError(.Range("A" & i).Value) = True And Application.IsError(.Range("B" & i).Value) = True Then
            .Range("A" & i).Value = ""
            .Range("B" & i).Value = ""
        End If
    Next i
    
    ActiveWorkbook.Worksheets("DataPrep").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("DataPrep").Sort.SortFields.Add Key:=Range("A:A") _
        , SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    With ActiveWorkbook.Worksheets("DataPrep").Sort
        .SetRange Range("A:A")
        .Header = xlYes
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
    
    ActiveWorkbook.Worksheets("DataPrep").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("DataPrep").Sort.SortFields.Add Key:=Range("B:B") _
        , SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    With ActiveWorkbook.Worksheets("DataPrep").Sort
        .SetRange Range("B:B")
        .Header = xlYes
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
    
    End With
    
    End Sub
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  4. #4
    Forum Contributor
    Join Date
    08-23-2011
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    404

    Re: Copying/pasting data & delete row up according to criteria

    Thanks Arlette! Works like a charm!

    (Sorry Pichingualas - Yes that is what I meant).

    Thank you very much for you time.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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