Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

For Each loop

Status
Not open for further replies.

UnsolvedCoding

Technical User
Jul 20, 2011
424
US
I am having problems with this sub and its probably something obvious.

The purpose is to capture the last three numbers on the worksheets and list them on a worksheet called INFO in descending order in column B.

Whats wrong?

Code:
Public WS As Worksheet
Public A As Integer

Sub Get_Number()

    A = 5
    
    For Each WS In ThisWorkbook.Worksheets
    
        If Format(Left(Application.Proper(WORKSHEETNAME), 2), ">") = "IO" Then
            Sheets("Info").Range("B" & A).Value = Right(Application.Proper(WORKSHEETNAME), 3)
            A = A + 1
        End If
    
    Next WS
End Sub

It has taken me a while to make sense of what I hear at work involving computers. There is much talk of bugs and questions about Raid.
Therefore I have come to the logical conclusion that the only way to have a properly functioning computer is to regularly spray it with Raid bug killer.
 
I figured it out by accident. It should be as follows -

Code:
Public WS As Worksheet
Public A As Integer

Sub Get_Number()
    A = 5
    For Each WS In ThisWorkbook.Worksheets
        If Format(Left(Application.Proper(WS.Name), 2), ">") = "IO" Then
            Sheets("Info").Range("B" & A).Value = Right(Application.Proper(WS.Name), 3)
            A = A + 1
        End If
    Next WS
End Sub

It has taken me a while to make sense of what I hear at work involving computers. There is much talk of bugs and questions about Raid.
Therefore I have come to the logical conclusion that the only way to have a properly functioning computer is to regularly spray it with Raid bug killer.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top