+ Reply to Thread
Results 1 to 6 of 6

Correction in code to re arrange data

Hybrid View

  1. #1
    Registered User
    Join Date
    03-07-2014
    Location
    london
    MS-Off Ver
    Excel 2016
    Posts
    83

    Correction in code to re arrange data

    HI All

    the result of the of the macro is in tab Capitalisation

    Below macro filters the right data in Site_assumptions and arranges into Capitalisation tab

    Example

    AT2 Krottenbach Jul-71 New sites Nov-17


    However i need to add in column F "Engineers" and "Site finders" per site and i don't know how to write that


    Hence it has to look like :

    AT2 Krottenbach Jul-71 New sites Nov-17 Engineers
    AT2 Krottenbach Jul-71 New sites Nov-17 Site finders



    manyb thanks!

    Sub CAPITALISATION()
    Application.ScreenUpdating = False
        Sheets("CAPITALISATION").Cells(1).CurrentRegion.Offset(1).ClearContents
        'the current region only works if the columns and rows next to it are blank
       With Sheets("SITE_ASSUMPTIONS").Range("p9").CurrentRegion
            .Parent.AutoFilterMode = False
            ' colum to filter is 4
            '7 is part of the formula is always 7
            .AutoFilter 4, Array("Renovation", "New sites"), 7
            .Copy Sheets("CAPITALISATION").Cells(1)
            .AutoFilter
        End With
    End Sub
    Attached Files Attached Files

  2. #2
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Correction in code to re arrange data

    Try this:

    Sub NEW_SITES_RENOVATIONS(): Dim r As Long
    'Application.ScreenUpdating = False
        Sheets("CAPITALISATION").Cells(1).CurrentRegion.Offset(1).ClearContents
        'the current region only works if the columns and rows next to it are blank
       With Sheets("SITE_ASSUMPTIONS").Range("p9").CurrentRegion
            .Parent.AutoFilterMode = False
            ' colum to filter is 4
            '7 is part of the formula is always 7
            .AutoFilter 4, Array("Renovation", "New sites"), 7
            .Copy Sheets("CAPITALISATION").Cells(1)
            .AutoFilter
        End With
        With Sheets("CAPITALISATION"): r = 2
        Do Until .Range("D" & r).Value = ""
        If .Range("D" & r).Value = "New sites" Then
        .Range("A" & r).Resize(1, 5).Copy: .Rows(r + 1).Insert
        .Range("F" & r).Value = "Engineers": r = r + 1
        .Range("F" & r).Value = "Site Builders"
        End If: r = r + 1: Loop
        End With
        Application.CutCopyMode = False
    End Sub
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  3. #3
    Registered User
    Join Date
    03-07-2014
    Location
    london
    MS-Off Ver
    Excel 2016
    Posts
    83

    Re: Correction in code to re arrange data

    Hi your code only works for 1 site

    it doesn't include the "Engineers" and "site finders" in code AT3

    Code Name Opening Status Action date CAPITALISING COSTS
    AT2 Krottenbach Jul-71 New sites Nov-17 Engineers
    AT2 Krottenbach Jul-71 New sites Nov-17 Site Builders
    AT3 Linz Lastenstrasse Feb-72 Renovation Apr-18


    thanks in advance

    AC

  4. #4
    Registered User
    Join Date
    03-07-2014
    Location
    london
    MS-Off Ver
    Excel 2016
    Posts
    83

    Re: Correction in code to re arrange data

    thanks anyway

  5. #5
    Registered User
    Join Date
    03-07-2014
    Location
    london
    MS-Off Ver
    Excel 2016
    Posts
    83

    Re: Correction in code to re arrange data

    THIS CODE WORKS BETTER

    Sub CAPITALISATION():
    Dim Lst As Long, n As Long
    'Application.ScreenUpdating = False
        Sheets("CAPITALISATION").Cells(1).CurrentRegion.Offset(1).ClearContents
        'the current region only works if the columns and rows next to it are blank
       With Sheets("SITE_ASSUMPTIONS").Range("p9").CurrentRegion
            .Parent.AutoFilterMode = False
            ' colum to filter is 4
            '7 is part of the formula is always 7
            .AutoFilter 4, Array("Renovation", "New sites"), 7
            .Copy Sheets("CAPITALISATION").Cells(1)
            .AutoFilter
        End With
     With Sheets("CAPITALISATION")
      Lst = .Range("A" & Rows.Count).End(xlUp).Row
        For n = Lst To 2 Step -1
          With .Range("F" & n)
              .EntireRow.Copy
              .Offset(1).EntireRow.Insert
              .Resize(2).Value = Application.Transpose(Array("Engineers", "Site finders"))
         End With
         Next n
    End With
    End Sub

  6. #6
    Valued Forum Contributor WasWodge's Avatar
    Join Date
    08-02-2010
    Location
    Hampshire,England
    MS-Off Ver
    Office 365 and Office 2010
    Posts
    882

    Re: Correction in code to re arrange data

    Was also cross-posted here
    If my solution worked (or not) please let me know. If your question is answered then please remember to mark it solved

    Computers are like air conditioners. They work fine until you start opening windows. ~Author Unknown

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Correction in code to refresh data when doing amendments
    By antonio32 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-17-2017, 11:43 AM
  2. Replies: 3
    Last Post: 07-21-2017, 06:18 AM
  3. VB Code to split and arrange data
    By rizmomin in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-11-2016, 12:55 AM
  4. Help needed to re-arrange data is a specific manner using macro/code
    By umairaasem in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 11-28-2014, 09:41 AM
  5. VBA code to arrange data obtain from website
    By Mob in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-15-2011, 08:37 AM
  6. Modification of VBA code to arrange data.
    By fatalcore in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-14-2011, 02:14 PM
  7. Help with code to re-arrange data for pareto analysis
    By Steve S in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-23-2006, 03:10 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