0

Hi just trying to run a code on every sheet in a workbook. For some reason it wont delete the column as specified. I've also tried using Columns(“A”).Delete and that did not work either

Sub Format()

'Firstly convert all text cells into number cells for every sheet in workbook

For Each WS In Sheets
    On Error Resume Next
    For Each r In WS.UsedRange.SpecialCells(xlCellTypeConstants)
        If IsNumeric(r) Then r.Value = (r.Value) * 1
        ''Or test the values in the next column on the right
        'If IsNumeric(r) Then r.Offset(0,1).Value = (r.Value)*1
    Next r

    Rows("1:15").Delete
    Columns(“1”).Delete


Next WS

End Sub
1
  • 1
    Columns("A") would work, as long as you also specified the worksheet: ws.Columns("A").Delete Commented Jan 15, 2020 at 3:33

1 Answer 1

2

You aren't qualifying those references with the sheet... it should look like this:

WS.Rows("1:15").Delete
WS.Columns(1).Delete

If you don't do that, then it just assumes ActiveSheet each time it loops.

Notice also that you do not put the 1 for columns in quotes. The 1 is an index value, not a string value.

Also, the type of quotes you are using is wrong. Look closely:

WS.Columns(“A”).Delete  ' <--- these curly quotes will not work (they are not the same thing)

WS.Columns("A").Delete  ' <--- these straight quotes work

straight and curly quotes

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.