Correction in code to re arrange dat

ANTONIO1981

Board Regular
Joined
Apr 21, 2014
Messages
162
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 as an example of site AT2, it has to look like :

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


I
have below code but is only working well for site AT2 , the rest of sites don't add Engineers and site finders

(attached) CAPITALISATION.xlsb - Google Drive

Code:
Sub CAPITALISATION(): 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 finders"
    End If: r = r + 1: Loop
    End With
    Application.CutCopyMode = False
End Sub
[COLOR=#333333]

[/COLOR]

thanks in advance

AC
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Perhaps this:-
Code:
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
 
Upvote 0
HI

Many thanks it works the only thing is that once macro finishes , it lefts selected row 2 in tab capitalisation

thanks in advance

ac
 
Upvote 0
You need to add this to bottom of code .
Code:
Application.CutCopyMode = False



Try this for your latest query !!!!
Code:
[COLOR="Navy"]Sub[/COLOR] MG27Aug49
[COLOR="Navy"]Dim[/COLOR] n [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long,[/COLOR] c [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long,[/COLOR] Ac [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long,[/COLOR] Ray [COLOR="Navy"]As[/COLOR] Variant, t
  t = Timer
  Ray = Sheets("SITE_ASSUMPTIONS").Range("p9").CurrentRegion
    ReDim nray(1 To UBound(Ray, 1) * 2, 1 To 6)
        [COLOR="Navy"]For[/COLOR] n = 2 To UBound(Ray, 1)
            [COLOR="Navy"]If[/COLOR] Ray(n, 4) = "New sites" Or Ray(n, 4) = "Renovation" [COLOR="Navy"]Then[/COLOR]
                c = c + 1
                [COLOR="Navy"]For[/COLOR] Ac = 1 To 5
                     nray(c, Ac) = Ray(n, Ac)
                     nray(c, 6) = "Engineers"
                  [COLOR="Navy"]Next[/COLOR] Ac
                  c = c + 1
                  [COLOR="Navy"]For[/COLOR] Ac = 1 To 5
                    nray(c, Ac) = Ray(n, Ac)
                    nray(c, 6) = "Site Finders"
                [COLOR="Navy"]Next[/COLOR] Ac
            [COLOR="Navy"]End[/COLOR] If
[COLOR="Navy"]Next[/COLOR] n
[COLOR="Navy"]With[/COLOR] Sheets("CAPITALISATION")
    .Cells(1).CurrentRegion.Offset(1).ClearContents
    .Range("A2").Resize(c, 6) = nray
[COLOR="Navy"]End[/COLOR] With
MsgBox Timer - t
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,157
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top