Live Chat & Podcast at 1:00PM Eastern on Sunday!
There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
Search
Business Applications
Tag Cloud
access acer asus bios bsod computer crash desktop dns driver drivers error ethernet excel freeze gaming graphics hard drive hardware hdmi internet laptop malware memory monitor motherboard network printer problem ram registry repair router slow software sound trojan ubuntu 11.10 uninstall usb video virus vista wifi windows windows 7 windows 7 32 bit windows 7 64 bit windows xp wireless
Search
Search for:
Tech Support Guy Forums > Software & Hardware > Business Applications >
Solved: Excel Macro -> Delete Multiple Rows

Reply  
Thread Tools
computerman29642's Avatar
Computer Specs
Senior Member with 2,794 posts.
 
Join Date: Dec 2007
Location: HERE OR THERE?!?!?!
Experience: Always Learning!
20-Nov-2009, 09:30 AM #31
Zack, the problem is that I am not sure how to handle the second find.

In the code I store the active sheet's (not the sheet where the data will be deleted) to a variable. I use that variable as the search criteria in the first find.

Do I need to store the next worksheet's name to a variable as well, and use that in the second find criteria?
__________________
Computerman29642
"Why so serious?....let's put a smile on that face" - The Joker
computerman29642's Avatar
Computer Specs
Senior Member with 2,794 posts.
 
Join Date: Dec 2007
Location: HERE OR THERE?!?!?!
Experience: Always Learning!
20-Nov-2009, 10:22 AM #32
I believe I have come up with a working code that should work.

Code:
Dim r1 As Range, r2 As Range, ws As Worksheet, x As Variant
    
    Set ws = Sheets("Main") 'Sheet that houses the data to be deleted when button on another sheet is pressed
    
    x = ActiveSheet.Name 'Variable that stores the name of the active sheet (sheet with deletion button)
    
    Set r1 = ws.Columns(1).Find(what:=x, after:=ws.Cells(1, 1)) 'Finds what is stored in the variable x

    Set r2 = ws.Columns(1).Find(what:="The header for the row", after:=r1).Offset(1, 0) 'Finds the row header of what should be the last row in teh group of data

    If r2.Row <= r1.Row Then
        'bad range
    Else
        ws.Activate 'Activates the main sheet
    'good range, use range here...
        ws.Range(r1, r2).Select '.EntireRow.Delete
    End If
The code works by running from a button on another sheet. The first find searches the main worksheet for the name of the active sheet (sheet that contains the button). The second find searches the for the row header for the group set (this should always be the last row in teh group/set of data) on the main sheet with the offset moving down one row (which will be the blank row between data groups/sets). Then the deletion happens.

Does anyone see any problems with the code?
__________________
Computerman29642
"Why so serious?....let's put a smile on that face" - The Joker
Zack Barresse's Avatar
Computer Specs
Distinguished Member with 5,030 posts.
 
Join Date: Jul 2004
Location: Oregon, United States
Experience: I'ma learnin'!
20-Nov-2009, 03:19 PM #33
No, I didn't use the activesheet, I referenced it explicitly. And I didn't select anything, so it shouldn't select the row, but delete it. I don't understand where that's coming from. Can you post a sample workbook? I don't know if I'll have time today, leaving in a bit, maybe later tonight, but I will be out through the weekend (school stuff).
computerman29642's Avatar
Computer Specs
Senior Member with 2,794 posts.
 
Join Date: Dec 2007
Location: HERE OR THERE?!?!?!
Experience: Always Learning!
20-Nov-2009, 03:35 PM #34
Quote:
No, I didn't use the activesheet, I referenced it explicitly. And I didn't select anything, so it shouldn't select the row, but delete it. I don't understand where that's coming from.
I changed it so that it would do a select instead of a delete. I did that for testing purposes.
Reply

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.

Search Tech Support Guy

Find the solution to your
computer problem!




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who want to help you solve your computer problems. See our Welcome Guide to get started.
Thread Tools



Facebook Facebook Twitter Twitter TechGuy.tv TechGuy.tv Mobile TSG Mobile
You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 09:51 PM.
Copyright © 1996 - 2011 TechGuy, Inc. All rights reserved.

Powered by Cermak Technologies, Inc.