+ Reply to Thread
Results 1 to 3 of 3

Range Selection Problem

Hybrid View

  1. #1
    Forum Contributor boylejob's Avatar
    Join Date
    02-22-2007
    Location
    Forest City, NC
    MS-Off Ver
    2003
    Posts
    562

    Range Selection Problem

    I am having a problem with selecting a range for some reason tonight. I have tried everything I know to do and nothing seems to be helping.

    Here is all of the code
    Sub FormatData()
    
    Dim wsPell As Worksheet
    Dim wsFormat As Worksheet
    Dim lLastRow As Long
    Dim lRow As Long
    Dim lFormatRow As Long
    Dim lPellAmt As Long
    Dim sTemp As String
    
    Set wsPell = Sheets(tabname)
    Set wsFormat = Sheets("Formatted")
    
    wsFormat.Cells.ClearContents
    
    lLastRow = wsPell.Cells(Rows.Count, 1).End(xlUp).Row
    lFormatRow = 1
    
    For lRow = 2 To lLastRow Step 1
    
        SSN = wsPell.Cells(lRow, 1).Value
        Name = wsPell.Cells(lRow, 3).Value + ", " + wsPell.Cells(lRow, 4).Value + _
           " " + wsPell.Cells(lRow, 5)
        If TermSel = "All" Then
            lPellAmt = wsPell.Cells(lRow, 6).Value + wsPell.Cells(lRow, 7).Value + _
            wsPell.Cells(lRow, 8).Value
        Else
            lPellAmt = wsPell.Cells(lRow, column).Value
        End If
    
        If lPellAmt > 0 Then
            wsFormat.Cells(lFormatRow, 1).Value = "DOE"
            wsFormat.Cells(lFormatRow, 2).Value = SSN
            wsFormat.Cells(lFormatRow, 3).Value = Name
            wsFormat.Cells(lFormatRow, 4).Value = lPellAmt
            lFormatRow = lFormatRow + 1
        End If
        lPellAmt = 0
        
    Next lRow
    
    wsFormat.Range(wsFormat.Cells(1, 1), wsFormat.Cells(lFormatRow - 1, 4)).Range.Select
    
    Set wsPell = Nothing
    Set wsFormat = Nothing
    
    End Sub
    This is the line that is giving me the problem (4th up from the bottom)
    wsFormat.Range(wsFormat.Cells(1, 1), wsFormat.Cells(lFormatRow - 1, 4)).Range.Select
    Everytime I run the code I get "Select method of Range Class failed"

    This has got to be something simple. Maybe I am just tired and need to go home for the night!

    Does anyone have any suggestions!
    Sincerely,
    Jeff

  2. #2
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,887
    Do you realize you have the "Range" property twice in that line?

    wsFormat.Range(wsFormat.Cells(1, 1), wsFormat.Cells(lFormatRow - 1, 4)).Range.Select
    Update: You may also need a line before that to activate the sheet if it's not the active sheet, e.g.
    wsFormat.Activate
    Last edited by Paul; 06-01-2007 at 11:50 PM.

  3. #3
    Forum Contributor boylejob's Avatar
    Join Date
    02-22-2007
    Location
    Forest City, NC
    MS-Off Ver
    2003
    Posts
    562
    pjoaquin,

    I forgot to take the second range out of my post. That was one of those "I know it is wrong, but let's try it anyway" type of things.

    What you sent
    wsFormat.Activate
    fixed the problem. I knew it was something simple. It has just been a long day and the old brain is not quite up to speed.

    Thanks a bunch for the help!

+ Reply to Thread

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