0

Hi all I am very new to the vba scene! I am having trouble with this code. I have been trying to work out what is happening with it... When I press F8 there is no error code coming up but it keeps on looping in the if statements

Sub testing()
Dim ws As Worksheet
Dim xRow As Integer
xRow = 1


With Me
    .Columns(1).ClearContents
    .Cells(1, 1) = "ROLES"
    .Cells(1, 1).Name = "Roles"
End With

For Each ws In Application.Worksheets
    If ws.Name <> Me.Name Then
        xRow = xRow + 1
        With ws
            .Range("A1").Name = "Start_" & ws.Index
        End With
    End If
Next
Application.Sceeenupdating = True

End Sub

13
  • Use F5 instead of F8 to run through the entire subroutine Commented Jun 26, 2017 at 14:23
  • @CodyG It comes up with this error- 'Object doesn't support this property' when I press f5 Commented Jun 26, 2017 at 14:27
  • 1
    Are you sure your code is working. Visually I can see that It will fail on With Me and If ws.Name <> Me.Name Then and then on Application.Sceeenupdating = True Commented Jun 26, 2017 at 14:27
  • @SiddharthRout Um when I tried to debug it using f8, it goes past that part fine. Commented Jun 26, 2017 at 14:27
  • Learning debugging - which line of code has the issue when you press F5 ? There are a few ways to do this. I would comment out the .Range line. Or I would put a print statement at the .Range line with the xRow and ws name Commented Jun 26, 2017 at 14:30

2 Answers 2

2

Are you sure your code is working. Visually I can see that It will fail on With Me and If ws.Name <> Me.Name Then and then on Application.Sceeenupdating = True – Siddharth Rout 11 mins ago

So you want the names of all the sheets in Col 1 of Sheet1? – Siddharth Rout 2 mins ago edit

@SiddharthRout yes exactly – Zoe Chu 13 secs ago

Is this what you are trying?

Sub testing()
    Dim ws As Worksheet, wsMain As Worksheet
    Dim xRow As Long

    '~~> This is the sheet which will have sheet names
    '~~> in Col 1 ("A")
    Set wsMain = ThisWorkbook.Sheets("Sheet1")

    Application.ScreenUpdating = False

    With wsMain
        .Columns(1).ClearContents
        .Cells(1, 1) = "ROLES"
        .Cells(1, 1).Name = "Roles"

        xRow = 2

        For Each ws In ThisWorkbook.Worksheets
            If ws.Name <> wsMain.Name Then
                .Cells(xRow, 1).Value = ws.Name
                xRow = xRow + 1
            End If
        Next
    End With

    Application.ScreenUpdating = True
End Sub
Sign up to request clarification or add additional context in comments.

5 Comments

Hiya, its now highlighting the 'Application.Screenupdating=True' now
I tested the code before posting :) There is nothing wrong with that line.
Man.. What am I missing
Where have you pasted the code? And did you make any changes to my code?
Thanks again! @SiddharthRout
1

Application.Sceeenupdating = True

should be

Application.ScreenUpdating = True

This would be a little more obvious if you set the following option in the VBA editor:

Tools > Options> Set Error Trapping to "Break on All Errors"

error trapping

Which should then pop up with

enter image description here

Clicking debug gets you to...

enter image description here

1 Comment

Ahh! Okay. I thought I was going crazy when people were talking about a 4 button error message box.

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.