Results 1 to 5 of 5

error:Statement invalid outside type block

Threaded View

  1. #3
    Registered User
    Join Date
    06-04-2010
    Location
    NY,USA
    MS-Off Ver
    Excel 2003
    Posts
    3

    Re: error:Statement invalid outside type block

    Quote Originally Posted by romperstomper View Post
    1. Which line gives you the error?
    2. Why post a picture, rather than a sample workbook? It would also help if you explained why you think the sort won't do what you want, as well as what you actually do want.

    Thanks romperstomper for replying.

    1. I was able to solve the first problem of the error: Statement invalid outside type block just a few minutes back. I had forgotten to add Dim infront of myRange

    2. I need help with the second part that is sort the rows in each column according to color such that the Red colored cells are on the top and the blue colored on the bottom for each column.

    I pasted a link of the picture of the worksheet to give an example of the format of the data I am dealing with. This time I attach the worksheet to this post for convinience of the readers.

    below is also the edited code that doesnot throw the Statement invalid outside type block error
    Sub Macro2()
    '
    ' Macro2 Macro
    '
    ' define the col range
    
        For Each currentHeaderColumn In Worksheets("Sheet1").Range("D1", Selection.End(xlEnd))
            Debug.Print "Currently processing Column:" & vbTab & currentHeaderColumn.Column
            Dim r As Range
            Dim ca As String
            ca = Cells(2, currentHeaderColumn.Column).Address
            Set r = Range(ca).End(xlDown)
            Debug.Print "Total number of rows:" & vbTab & r.Row
    '       my $ @ %
            Dim myRange As Range ' this was the line that gave the errror before
            Set myRange = Worksheets("Sheet1").Range(ca, Cells(2, r.Row).Address)
            For Each currentCellInCurrentColRange In myRange
           
            ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Add(Range(myRange), _
            xlSortOnCellColor, xlAscending, , xlSortNormal).SortOnValue.Color = RGB(255, 0 _
            , 0)
           
            
                Debug.Print currentCellInCurrentColRange.Value
           Next currentCellInCurrentColRange
        Next currentHeaderColumn
        
    
      
      End Sub
    Attached Files Attached Files

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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