Results 1 to 6 of 6

Thread: selecting a row with a variable

  1. #1

    Thread Starter
    Member
    Join Date
    Jul 2003
    Location
    Los Angeles, CA
    Posts
    49

    selecting a row with a variable

    VB Code:
    1. For a = 4 To last
    2.     If Sheets("Software Personnel").Range("K" & a).Value = "M760" Then
    3.         Sheets("Software Personnel").Select
    4.         Rows(a).Select
    5.         Selection.Cut
    6.         Sheets("M760 Personnel").Select
    7.         Rows(m760Last + count).Select
    8.         ActiveSheet.Paste
    9.         count = count + 1
    10.     End If
    11. Next

    When I try to run this code... I get an error "1004 Select Method of Range class failed" and doesn't like this line:

    VB Code:
    1. Rows(a).Select

    Any ideas? Any different algorithms that would work?

    Thanks,
    Alex
    Last edited by LodBot; Jul 29th, 2003 at 12:50 PM.

  2. #2
    PowerPoster lintz's Avatar
    Join Date
    Mar 2003
    Location
    The 19th Hole
    Posts
    2,697
    This is how I highlight a row.....hope it helps

    Code:
    oXLApp.Worksheets("Sheet1").Select
    ActiveCell.EntireRow.Select
    Selection.Delete Shift:=xlUp

  3. #3

    Thread Starter
    Member
    Join Date
    Jul 2003
    Location
    Los Angeles, CA
    Posts
    49
    thanks

  4. #4

    Thread Starter
    Member
    Join Date
    Jul 2003
    Location
    Los Angeles, CA
    Posts
    49
    VB Code:
    1. For a = 1 to 20
    2.      Sheets("New Personnel").Range("BB" & a).EntireRow.Select
    3.      Selection.Cut
    4.      Selection.Delete Shift:=xlUp
    5. Next

    I get:

    1004 Select method of Range class failed
    and it doesn't like this line:

    Sheets("New Personnel").Range("BB" & a).EntireRow.Select
    any ideas?
    Last edited by LodBot; Jul 29th, 2003 at 12:56 PM.

  5. #5
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538
    This works fine for me, have you declared a as an integer variable data type?

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

  6. #6
    Fanatic Member Matt_T_hat's Avatar
    Join Date
    Dec 2001
    Location
    '76 Male Body Evil-Errors: 666
    Posts
    774
    Is there a reason why Vlookup is not an option? Vlookup displays information from one cell by finding something in another. It's also be fast I would have thought.
    ?
    'What's this bit for anyway?
    For Jono

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width