+ Reply to Thread
Results 1 to 7 of 7

Help with function to organise some data

Hybrid View

  1. #1
    Forum Expert dilipandey's Avatar
    Join Date
    12-05-2011
    Location
    Dubai, UAE
    MS-Off Ver
    1997 - 2016
    Posts
    8,191

    Re: Help with function to organise some data

    Hi Snowtoad,

    Apologies, I have missed this one.
    Here you go, assuming you have your data arranged in column A to C, use following quick code (though it needs little improvisation but still it will work):-

    Sub Macro4()
    Application.ScreenUpdating = False
    
        Cells(1, 1).Select
        Selection.CurrentRegion.Select
        
        ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:= _
            "Sheet1!R1C1:R11C3").CreatePivotTable TableDestination:="", TableName:= _
            "PivotTable5", DefaultVersion:=xlPivotTableVersion10
    
        ActiveSheet.PivotTables("PivotTable5").AddFields RowFields:=Array("Site", _
            "Author-Year")
        ActiveSheet.PivotTables("PivotTable5").PivotFields("Site").Orientation = _
            xlDataField
    
        ActiveSheet.PivotTables("PivotTable5").PivotSelect "", xlDataAndLabel, True
        Selection.Cut
        Range("A1").End(xlToRight).Select
     
        ActiveCell.Offset(0, -3).Range("A1").Select
        ActiveSheet.Paste
    
        Selection.Copy
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
        ActiveCell.Offset(1, 0).Select
        
    While ActiveCell.Value <> ""
    Selection.Offset(1, 1).Select
        If Selection.Offset(1, 0).Value = "" Then
        Selection.Copy
        Else
        Range(Selection, Selection.End(xlDown)).Copy
        End If
        Selection.Offset(0, -1).Select
        If Selection.Offset(1, 0).Value = "" Then
        Selection.End(xlDown).Select
        Else
        Selection.Offset(1, 0).Select
        End If
        
        Selection.End(xlToLeft).Select
            Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=True
        ActiveCell.Select
        If Selection.Offset(0, 1).Value = "" Then
        
        Selection.End(xlToRight).Select
        Else
        Selection.End(xlToRight).Select
        Selection.End(xlToRight).Select
        End If
    Wend
    
    Range("a1").End(xlToRight).Select
    
    ActiveCell.Offset(0, -1).Formula = "=IF(ISNUMBER(SEARCH(""total"",RC[1])),""n"",""y"")"
    Selection.Offset(0, -1).Select
        Selection.End(xlDown).Select
        Selection.End(xlDown).Select
        ActiveCell.Offset(0, 1).Range("A1").Select
        Selection.End(xlUp).Select
        ActiveCell.Offset(0, -1).Range("A1").Select
        Range(Selection, Selection.End(xlUp)).Select
        Range(Selection, Selection.End(xlUp)).Select
        Selection.FillDown
    
    While ActiveCell.Value <> ""
        If ActiveCell.Value = "y" Then
        ActiveCell.EntireRow.Delete
        Else
        ActiveCell.Offset(1, 0).Select
        End If
    Wend
    Selection.EntireColumn.Delete
    Selection.Offset(-1, 1).Select
    Selection.EntireColumn.Delete
    Selection.CurrentRegion.Copy
    Range("a1").End(xlToRight).Offset(0, 1).Select
    Selection.PasteSpecial
    Selection.End(xlDown).Select
    Selection.EntireRow.Delete
    Cells(1, 1).Select
    Application.ScreenUpdating = True
    End Sub
    Let me know if you need further assistance. Thanks.

    Regards,
    DILIPandey

    <click on below 'star' if this helps >
    DILIPandey, Excel rMVP
    +919810929744 (India), +971528225509 (Dubai), dilipandey@gmail.com

  2. #2
    Registered User
    Join Date
    05-25-2010
    Location
    Australia
    MS-Off Ver
    Excel 2007
    Posts
    26

    Re: Help with function to organise some data

    Thanks so much for the effort! However it didn't seem to work..
    Here's the data I'm working with.. it did something but not at all like it's supposed to.

    Cheers!

    Study Site Data.xlsm

+ 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