Results 1 to 2 of 2

problem with Range statement in With-End With loop

Threaded View

  1. #1
    Valued Forum Contributor
    Join Date
    02-21-2010
    Location
    Tokyo, Japan
    MS-Off Ver
    Excel 2007
    Posts
    502

    problem with Range statement in With-End With loop

    In the sub below the following code gives an error.

    With Sheets("Author ranking").Range(Cells(2, LastColumn), Cells(LastRow, LastColumn))
    The problem is definetely with this line, because if I specify the Range to Range("D:D") the sub is working.
    What is wrong here?
    I attached a test Excel sheet with the macro.

    Sub Macro1()
    
        Dim LastColumn As Long
        Dim LastColumnJ As Long
        Dim LastRow As Long
        Dim LastRow2 As Long
        Dim JAuth2Rw    As Long
        Dim Auth2Rw     As Long
        Dim NextRw      As Long
        Dim JAuthName   As String
        Dim AuthName    As String
        Dim strFirstAddress As String
        
        Sheets("J-Author ranking").Select
        
        LastColumn = Sheets("Author ranking").Cells(1, Columns.Count).End(xlToLeft).Column
        LastColumnJ = Sheets("J-Author ranking").Cells(1, Columns.Count).End(xlToLeft).Column
        
        LastRow = Sheets("Author ranking").Cells(Rows.Count, LastColumn).End(xlUp).Row
        LastRowJ = Sheets("J-Author ranking").Cells(Rows.Count, LastColumnJ).End(xlUp).Row
    
        
        For JAuth2Rw = 2 To LastRowJ
            JAuthName = Sheets("J-Author ranking").Cells(JAuth2Rw, LastColumnJ)
                
            With Sheets("Author ranking").Range(Cells(2, LastColumn), Cells(LastRow, LastColumn))
                Set rngFoundCell = .Find(What:=JAuthName, After:=.Cells(1, 1), LookAt:=xlPart)
                If Not rngFoundCell Is Nothing Then
                    strFirstAddress = rngFoundCell.Address
                    Do
                        
                        Sheets("J-Author ranking").Hyperlinks.Add Anchor:=Cells(JAuth2Rw, LastColumnJ), Address:="", _
                            SubAddress:="'Author ranking'!" & rngFoundCell.Address
        
                        Set rngFoundCell = .FindNext(rngFoundCell)
                    Loop While Not rngFoundCell Is Nothing And rngFoundCell.Address <> strFirstAddress
                End If
            End With
        
        Next JAuth2Rw
    
    End Sub
    Attached Files Attached Files
    Last edited by dschmitt; 04-22-2010 at 04:24 AM.

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