?
Solved

Code to delete rows, add date and loop

Posted on 2014-07-11
6
Medium Priority
?
94 Views
Last Modified: 2014-07-17
Hi, i have attached a ss where i need some code to do the following with the three tabs highlighted green

(1) delete the first 3/4 rows so my headings are on the row 1
(2) Add a column named "Date" in Col AO and put in the current month in format mmm-yy

Loop through the three tabs highlightyed green doing the same

Thanks
LoopingSheetsCode.xlsx
0
Comment
Question by:Seamus2626
  • 3
  • 3
6 Comments
 
LVL 54

Expert Comment

by:Rgonzo1971
ID: 40190544
Hi,

pls try

Sub Macro1()
'
' Macro1 Macro
'


For Each sh In ThisWorkbook.Sheets
    If sh.Tab.Color = 5296274 Then
        sh.Activate
        Set Found = Range("A:A").Find("MasterGroup Name")
        Range(Range("A1"), Found.Offset(-1)).EntireRow.Delete
        With Range("AO1")
            .Value = "Date"
            .Interior.Color = vbRed
            .Font.Color = vbWhite
            .Font.Bold = True
            .HorizontalAlignment = xlCenter
            .EntireColumn.NumberFormat = "MMM-yy"
        End With
    End If
Next
    

End Sub

Open in new window

Regards
0
 

Author Comment

by:Seamus2626
ID: 40190550
Rgonzo, that looks great but i must note that i only coloured the sheets green, going forward they would have to referred to explicitly by their name!

Thanks
0
 
LVL 54

Accepted Solution

by:
Rgonzo1971 earned 2000 total points
ID: 40190558
No problem

Sub Macro1()
'
' Macro1 Macro
'


For Each sh In ThisWorkbook.Sheets
    Select Case sh.Name
        Case "Incountry", "Inbound", "Outbound"
            sh.Activate
            Set Found = Range("A:A").Find("MasterGroup Name")
            Range(Range("A1"), Found.Offset(-1)).EntireRow.Delete
            With Range("AO1")
                .Value = "Date"
                .Interior.Color = vbRed
                .Font.Color = vbWhite
                .Font.Bold = True
                .HorizontalAlignment = xlCenter
                .EntireColumn.NumberFormat = "MMM-yy"
            End With
        Case Else ' Nothing
    End Select
Next
    

End Sub

Open in new window

Regards
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Seamus2626
ID: 40190591
Hey Rgonzo,

The code is jumping straigh to Case Else?

Is that running fine for you?

Thanks
0
 
LVL 54

Expert Comment

by:Rgonzo1971
ID: 40192722
Running fine by me

Let's try

on your example I've inserted the code

Regards
0
 

Author Closing Comment

by:Seamus2626
ID: 40201474
Thanks!
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have had my own IT business for a very long time. I started mostly with hardware and after about a year started to notice a common theme. I had shelves with software boxes -- Peachtree, Quicken, Sage, Ouickbooks -- and yet most of my clients were…
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

569 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question