+ Reply to Thread
Results 1 to 2 of 2

Code with a loop: Green 'Run' Button does nothing?

  1. #1
    Registered User
    Join Date
    12-02-2020
    Location
    France
    MS-Off Ver
    2016
    Posts
    8

    Code with a loop: Green 'Run' Button does nothing?

    Hello all,

    I have some code that runs a loop. When I press the green 'run' button or F5, nothing happens at all.
    I don't think there are any errors in my code, but maybe it is the case that there is a line that I need to include/move.

    The loop opens docs one-by-one in a folder, changes the format the exact same way for each sheet per doc, saves the doc and closes the file.

    I cannot find how to format my code into a proper format too...sorry about this.

    'Loop
    Path = "File_path" (omitted for privacy)
    Filename = Dir(Path & "*.xl*")
    Do While Filename <> ""
    Workbooks.Open Filename:=Path & Filename

    'Enable editing
    If Not Application.ActiveProtectedViewWindow Is Nothing Then
    Application.ActiveProtectedViewWindow.Edit
    End If

    For Each Sheet In ActiveWorkbook.Sheets

    'Run macro in loop
    ActiveSheet.Pictures.Delete
    Rows("1:6").Select
    Range("A6").Activate
    Selection.Delete Shift:=xlUp
    Columns("F:F").Select
    Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
    Range("F1").Select
    ActiveCell.FormulaR1C1 = "Description"
    Range("F3").Select
    ActiveCell.FormulaR1C1 = ActiveWorkbook.Name
    Range("E3").Select
    Selection.Copy
    Range("F3").Select
    Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
    SkipBlanks:=False, Transpose:=False
    Application.CutCopyMode = False

    Selection.AutoFilter
    ActiveSheet.Range("$A$1:$V$1000").AutoFilter Field:=7, Criteria1:="0"
    Range("A1").Select
    Selection.Offset(1, 0).Select
    Range(Selection, Selection.End(xlToRight)).Select
    Range(Selection, Selection.End(xlToRight)).Select
    Range(Selection, Selection.End(xlToRight)).Select
    Range(Selection, Selection.End(xlToRight)).Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.Delete Shift:=xlUp

    ActiveSheet.Range("$A$1:$V$1000").AutoFilter Field:=7
    ActiveSheet.Range("$A$1:$V$1000").AutoFilter Field:=11, Criteria1:="0"
    Range("A1").Select
    Selection.Offset(1, 0).Select
    Range(Selection, Selection.End(xlToRight)).Select
    Range(Selection, Selection.End(xlToRight)).Select
    Range(Selection, Selection.End(xlToRight)).Select
    Range(Selection, Selection.End(xlToRight)).Select
    Range(Selection, Selection.End(xlToRight)).Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.Delete Shift:=xlUp

    ActiveSheet.Range("$A$1:$V$1000").AutoFilter Field:=11
    Range("A1").Select

    Next Sheet

    Sheet("Sheet1").Activate

    Workbooks(Filename).Close SaveChanges:=True
    Filename = Dir()
    Loop

    End Sub

    Thanks for any help and advice in advance!

    Lou

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Code with a loop: Green 'Run' Button does nothing?

    Does your Path end with a \
    e.g.
    Please Login or Register  to view this content.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

+ 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. Red/Green Shape with Reset Button
    By Sirenitie in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-18-2019, 05:01 AM
  2. [SOLVED] UserForm with Cancel Button to stop Loop Code
    By gsandy in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-06-2015, 03:07 PM
  3. [SOLVED] Help with code for a command button that changes strikethrough cells green
    By SerraAngel in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 11-05-2014, 01:59 AM
  4. Reset Macro Button Code in combination with a Loop
    By tnuis in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-30-2013, 06:09 AM
  5. Toggle button that changes color (say between red & green) for Inactive / Active
    By TrippKnightly in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 12-11-2012, 11:10 AM
  6. Ok button runs code 17 times w/o loop.... Why?
    By contaminated in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-28-2012, 05:19 AM
  7. Loop through sheets until tab colour is green
    By mattsgr1 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-28-2007, 09:39 AM

Tags for this Thread

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