Results 1 to 1 of 1

Help cleaning up data

Threaded View

  1. #1
    Registered User
    Join Date
    06-13-2011
    Location
    Boulder, Colorado
    MS-Off Ver
    Excel 2010
    Posts
    61

    Help cleaning up data

    I am currently writing a macro to analyze a lot of data that I have collected along with ym graduate student monitoring cell motility and cooperativity. The macro I included runs well and does everything I desire except in the beginning of the macro I have need to identify each cell by its trajectory or cell number. My process of doing this which is visible in column D works as I like but it fills some empty rows (that are present because of the tab delimited data format) with trajectories. Then for later analysis I copy these columns and sort them a different way but now these numbers I spoke of above are displayed at the very bottom of my sorted data and are causing errors in my next calculations. If anyone can think of a way to exclude these numbers or have my macro delete them I would greatly appreciate the help.

    I've uploaded a sample workbook with the macro already run. It's a relativley small sample but if you scroll to the bottom of columns G:R you can see the undesired data that is creating various errors. Also my macro is included below and please as always feel free to ask questions.

    Sub WillYouBeMyNeighbor()
    
    Dim M   As Long
    Dim LR  As Long
    Dim rngCell As Range
    Dim rCell As Range
    
    
    Selection.EntireRow.Insert , CopyOrigin:=xlFormatFromLeftOrAbove
    Selection.EntireRow.Insert , CopyOrigin:=xlFormatFromLeftOrAbove
    
    LR = Range("A" & Rows.Count).End(xlUp).Row
    M = Application.WorksheetFunction.Max(Range("A:A"))
    
    With Range("D4:F" & LR)
        .ClearContents
    End With
    
    With Range("D3:D" & LR)
    .FormulaR1C1 = "=IF(RC1=""%%"",RC[-1],R[-1]C)"
    End With
    
    'With Range("D3:D" & LR)
    '    .FormulaR1C1 = "=IF(ISNUMBER(RC[1],RC[-1],R[-1]C)"
    'End With
    
    'Report data with enhanced formatting
    
    Range("G3:T3").Value = [{"Frame","X","Y","Cell #","Dist","Proximity","Cell #","NN Frame +1","NN","NN X","NN Y","NN X+1","NN Y+1","Angle"}]
    
    With Range("G4:G" & LR)
        .FormulaR1C1 = "=IF(ISNUMBER(RC[-6]),RC[-6],"""")"
        .Value = .Value
    End With
    
    With Range("H4:H" & LR)
        .FormulaR1C1 = "=IF(ISNUMBER(RC[-6]),RC[-6],"""")"
        .Value = .Value
    End With
    
    With Range("I4:I" & LR)
        .FormulaR1C1 = "=IF(ISNUMBER(RC[-6]),RC[-6],"""")"
        .Value = .Value
    End With
    
    With Range("J4:J" & LR)
        .FormulaR1C1 = "=IF(ISNUMBER(RC[-6]),RC[-6],"""")"
        .Value = .Value
    End With
    
    'Sort Reported Values
    
    ActiveSheet.Sort.SortFields.Clear
        ActiveSheet.Sort.SortFields.Add Key:=Range( _
            "G3:G" & LR), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
            xlSortNormal
        With ActiveSheet.Sort
            .SetRange Range("G3:J" & LR)
            .Header = xlYes
            .MatchCase = False
            .Orientation = xlTopToBottom
            .SortMethod = xlPinYin
            .Apply
        End With
    
    'Distance Calcualtion
    
    With Range("K4:K" & LR)
        .FormulaR1C1 = "=SQRT((RC[-3]-R[1]C[-3])^2+(RC[-2]-R[1]C[-2])^2)"
    End With
    
    With Range("L4:L" & LR)
        .FormulaR1C1 = "=IF(RC[-1]<20,RC[-1],"""")"
    End With
    
    With Range("M4:M" & LR)
        .FormulaR1C1 = "=IF(RC[-1]="""","""",RC[-3])"
    End With
    
    With Range("N4:N" & LR)
        .FormulaR1C1 = "=IF(RC[-1]="""","""",RC[-7]+1)"
    End With
    
    With Range("O4:O" & LR)
        .FormulaR1C1 = "=IF(RC[-2]="""","""",R[1]C[-5])"
    End With
    
    With Range("P4:P" & LR)
      .FormulaR1C1 = "=IF(ISNUMBER(RC[-1]),R[1]C[-8],"""")"
    End With
    
    With Range("Q4:Q" & LR)
        .FormulaR1C1 = "=IF(ISNUMBER(RC[-1]),R[1]C[-8],"""")"
    End With
    
    
    For Each rngCell In Range("R4:R" & LR).Cells
        rngCell.FormulaArray = _
            "=IF(RC[-5]="""","""",INDEX(R4C[-10]:R" & LR & "C[-10],MATCH(RC[-4]&RC[-3],R4C[-11]:R" & LR & "C[-11]&R4C[-8]:R" & LR & "C[-8],0)))"
    Next rngCell
    
    For Each rngCell In Range("S4:S" & LR).Cells
        rngCell.FormulaArray = _
            "=IF(RC[-6]="""","""",INDEX(R4C[-10]:R" & LR & "C[-10],MATCH(RC[-5]&RC[-4],R[-2]C[-12]:R" & LR & " C[-12]&R[-2]C[-9]:R" & LR & "C[-9],0)))"
    Next rngCell
    
    With Range("T4:T" & LR)
        .FormulaR1C1 = _
            "=IF(RC[-8]="""","""",DEGREES(ATAN((RC[-1]-RC[-3])/(RC[-2]-RC[-4]))))"
    End With
    
    For Each rCell In Range("T4:T" & LR)
        If IsError(rCell) Then rCell = ""
    Next rCell
    
    'Average If's and STDEVIF's
    
    Range("V3:Y3").Value = [{"Frame","Ave Angle","STDEV","1/STDEV"}]
    Range("V4") = 0
    Range("V5").Resize(M).FormulaR1C1 = "= R[-1]C +1"
    
    With Range("W4:W" & M + 4)
        .FormulaR1C1 = _
            "=AVERAGEIF(RC[-16]:R271C[-16],RC[-1],RC[-3]:R271C[-3])"
    End With
    
    
    End Sub
    Attached Files Attached Files

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