0

I have the below code, but when I run the macro, it seems to ignore the fact that I've excluded the "Input" sheet. Any ideas? I'm aware there are probably other errors in the preceding code, but I'd like to fix this first!

Sub export_all()
Dim Path As String
Dim Name As String
Dim ws As Worksheet
Path = Workbooks("CGL Configurator V3.xlsm").Sheets("Input").Range("$C$12")
Name = ActiveSheet.Range("A151")
For Each ws In ThisWorkbook.Worksheets
    If ws.Name <> "Input" Then
        Range("A1:AZ151").Copy
        Workbooks.Add
        Range("A1").PasteSpecial Paste:=xlPasteValues
        ActiveWorkbook.SaveAs Filename:=Path & "\" & Name & ".csv", FileFormat:=xlCSVUTF8
        Range("A151").Delete
        ActiveWorkbook.Save
        ActiveWorkbook.Close
    End If
Next ws
Workbooks("CGL Configurator V3.xlsm").Sheets("Input").Activate
End Sub
3
  • 1
    What is it? Does it ignore your exclusion, or does it only seem to ignore it? The first thing I'd try is to set a breakpoint on the If statement, and then step through your code (F8) to see whats going on. Alternatively, add Debug.Print(ws.Name) inside that If statement.
    – Berend
    Nov 19, 2019 at 12:56
  • +1 for debug.print ws.Name on the next line, before Range("A1:AZ151").Copy. Alternatively, use an Else If ws.Name = "Input" then End If Nov 19, 2019 at 13:08
  • Thanks @Berend, F8 was useful, turns out I was missing a '.ws' before Range("A1:AZ151").Copy, so it was missing the Input sheet, but then copying cells off it anyway as it was the active sheet. Nov 19, 2019 at 14:58

1 Answer 1

0

turns out I was missing a '.ws' before Range("A1:AZ151").Copy, so it was missing the Input sheet, but then copying cells off it anyway as it was the active sheet.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .