VBA Macro Iteration

0 votes

The code executes the following straightforward macro in the same sheet, thus I must repeat it for each sheet. How do I change the code?

Sub Macro1()
'


' Macro1 Macro
'

Dim ws As Worksheet

    For Each ws In Worksheets
        With ws
            Application.Goto Reference:="R1C1"
            Cells.Select
            Selection.UnMerge
            Columns("D:D").Select
            Selection.Delete Shift:=xlToLeft
            Columns("E:E").Select
            Selection.Delete Shift:=xlToLeft
            Application.Goto Reference:="R10C9"
            Range("J10").Select
            Range(Selection, Selection.End(xlToRight)).Select
            Range(Selection, Selection.End(xlDown)).Select
            Selection.EntireColumn.Delete
        End With
    Next ws
End Sub
Mar 20, 2023 in Others by Kithuzzz
• 38,010 points
320 views

1 answer to this question.

0 votes

Try this:

Sub macro1()
' Macro1 Macro
'

Dim ws As Worksheet

    For Each ws In Worksheets
        With ws
            .Activate
            .Range("A1").Select
            .Cells.Select
            .Application.Selection.UnMerge
            .Columns("D:D").Select
            .Application.Selection.Delete Shift:=xlToLeft
            .Columns("E:E").Select
            .Application.Selection.Delete Shift:=xlToLeft
            .Application.Goto Reference:="R10C9"
            .Range("J10").Select
            .Range(Selection, Selection.End(xlToRight)).Select
            .Range(Selection, Selection.End(xlDown)).Select
            .Application.Selection.EntireColumn.Delete
        End With
    Next ws
End Sub
answered Mar 20, 2023 by narikkadan
• 63,420 points

Related Questions In Others

0 votes
1 answer

How do I use the Indirect Function in Excel VBA to incorporate the equations in a VBA Macro Function

Try this: Sub Test() Dim str As String: str ...READ MORE

answered Jan 19, 2023 in Others by narikkadan
• 63,420 points
637 views
0 votes
1 answer

My VBA macro slows down dramatically with each use

You have a function called ExportRange that ...READ MORE

answered Jan 21, 2023 in Others by narikkadan
• 63,420 points
442 views
0 votes
1 answer

VBA SharePoint macro

I believe you are attempting to open ...READ MORE

answered Feb 14, 2023 in Others by Kithuzzz
• 38,010 points
1,573 views
0 votes
1 answer

Autofill Copy down up until next empty row- Excel VBA Macro

Row 1048576 will be returned by end(xldown) ...READ MORE

answered Feb 18, 2023 in Others by narikkadan
• 63,420 points
1,057 views
0 votes
1 answer

Retrieve epay.info Balance with VBA and Excel

This code should log you in, provided ...READ MORE

answered Sep 5, 2018 in Blockchain by digger
• 26,740 points
877 views
0 votes
1 answer

How to load file to Excel Power query from SFTP site

Currently, I don't think there is a ...READ MORE

answered Dec 3, 2018 in Power BI by Upasana
• 8,620 points
3,183 views
0 votes
1 answer

Using VBA Excel to create a gramatically correct list

The Excel AND function is a logical ...READ MORE

answered Feb 9, 2022 in Others by gaurav
• 23,260 points
481 views
0 votes
2 answers

How to copy a formula horizontally within a table using Excel VBA?

Hi so basically, create an adjacent column ...READ MORE

answered Feb 16, 2022 in Others by Edureka
• 13,670 points
731 views
0 votes
1 answer

Creating an unique export data VBA Macro Function in Excel

Unfortunately, the tables will vary in size. ...READ MORE

answered Nov 14, 2022 in Others by narikkadan
• 63,420 points
487 views
0 votes
1 answer

Excel VBA is not recording macro properly

The "awkward code" is an R1C1 notation ...READ MORE

answered Nov 15, 2022 in Others by narikkadan
• 63,420 points
839 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP