Macro anger!!
Power Query Course in Spanish
Thanks Thanks:  0
Likes Likes:  0
Results 1 to 4 of 4

Thread: Macro anger!!

  1. #1
    Board Regular
    Join Date
    Feb 2002
    Location
    Where the wild roses grow
    Posts
    285
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

     

    How do I write a macro to do the following:

    Suppose the active cell is A1. I need to delete rows - 1,2,3,6,10,12,13 and 14.

    But I need to it be relative to where the active cell is. I've tried recording it but it keeps going back to A1 and doing the macro again. I need it to perform the task starting wherever the active cell is

    Any ideas?

  2. #2
    Rest in Peace
    Join Date
    Feb 2002
    Posts
    1,582
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Hi

    Try:

    ActiveCell.Range("A1,A2,A3,A6,A10,A12,A13,A14").EntireRow.Delete

    It's relative to the activecell


  3. #3
    Board Regular
    Join Date
    Feb 2002
    Location
    Where the wild roses grow
    Posts
    285
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Dave you are an angel!

  4. #4
    MrExcel MVP Mark O'Brien's Avatar
    Join Date
    Feb 2002
    Location
    Columbus, OH, USA
    Posts
    3,530
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

      
    Something like this should work, the row is offset based upon the activecell. I'm not sure if I recommend doing this since you can irreversibly delete data by mistake using "Activecell". Anyway, here's what you asked for:


    Option Base 1

    Public Sub DeleteRows()

    Dim iArray(8) As Integer
    Dim i As Integer

    iArray(1) = 1
    iArray(2) = 2
    iArray(3) = 3
    iArray(4) = 6
    iArray(5) = 10
    iArray(6) = 12
    iArray(7) = 13
    iArray(8) = 14

    For i = 8 To 1 Step -1 'step backwards since we're deleting rows
    ActiveCell.Offset(iArray(i), 0).Rows.Delete
    Next

    End Sub


User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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

 

 
DMCA.com