Current location: Hot Scripts Forums » Programming Languages » Other Languages » Help with Macro


Help with Macro

Reply
  #1 (permalink)  
Old 02-17-09, 09:06 AM
DarleneMiles DarleneMiles is offline
Newbie Coder
 
Join Date: Jan 2009
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Help with Macro

I have a macro that will delete rows that contain the word "Delete" (the data is sorted so that the word "Delete" is last). The problem I've run into is that not always will there be a word "Delete" and then my macro blows up. Can someone please help me put an IF statement around this code?

Code:
Columns("I:I").Select
Selection.Find(What:="Delete", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
ActiveCell.Select
Range(Selection, Selection.End(xlDown)).Select
Selection.EntireRow.Delete
Your help is appreciated!

Last edited by digioz; 02-18-09 at 08:56 AM. Reason: Please use code tags.
Reply With Quote
  #2 (permalink)  
Old 02-18-09, 05:13 AM
Yeroon's Avatar
Yeroon Yeroon is offline
Code Master
 
Join Date: Aug 2007
Location: Netherlands, Nijmegen
Posts: 850
Thanks: 2
Thanked 20 Times in 20 Posts
OK here ya go. Note that the rows with deleted in column i should always be sorted at the bottom!

Code:
Sub test()

    On Error GoTo myerror

    Columns("I:I").Select

    Selection.Find(What:="Delete", After:=ActiveCell, LookIn:=xlFormulas, _
    LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
    MatchCase:=False).Activate

    ActiveCell.Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.EntireRow.Delete

Exit Sub
myerror:

    If myerror.Number = 91 Then
        Resume Next
    End If


End Sub
__________________
Feel free to thank people if they help you by clicking thanks at a post.
=================================
Make it idiot proof and someone will make a better idiot.
=================================
Realise the impotence of proof reading everything you publish

Last edited by Yeroon; 02-18-09 at 05:18 AM.
Reply With Quote
  #3 (permalink)  
Old 02-18-09, 07:55 AM
DarleneMiles DarleneMiles is offline
Newbie Coder
 
Join Date: Jan 2009
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Thank you so much! What does the number error 91 mean?

Also, would you be able to help me with another macro, please? Our IT department does not have time to help me.

The code below always refers to the workbook "WMR 2.0 Template Phase 2.xls". What we really need is a macro that would copy these tabs into a workbook that has a specific name (i.e., This Workbook.xls). How can I copy tabs from another workbook and put in a workbook that has been named something other than "Active Workbook Template"? Thanks so much for any help you can provide!


Code:
Workbooks.Open Filename:= _
"C:\Performance Template.xls", UpdateLinks:=0, ReadOnly:=True
Sheets(Array("LCData1", "Returns1")).Select
Sheets(Array("LCData1", "Returns1")).Copy before:=Workbooks( _
"Active Workbook Template.xls").Sheets("BlankTab")

Last edited by digioz; 02-18-09 at 08:57 AM. Reason: Please use code tags.
Reply With Quote
  #4 (permalink)  
Old 02-18-09, 08:00 AM
Yeroon's Avatar
Yeroon Yeroon is offline
Code Master
 
Join Date: Aug 2007
Location: Netherlands, Nijmegen
Posts: 850
Thanks: 2
Thanked 20 Times in 20 Posts
Quote:
What does the number error 91 mean?
You can get the description like this. In this case it just checks if the selection is set to something. If it is Nothing then error 91 happens. We catch the error and resume.

Code:
    If myerror.Number = 91 Then
        MsgBox myerror.Description
        Resume Next
    End If
Will get back to you on your second question
__________________
Feel free to thank people if they help you by clicking thanks at a post.
=================================
Make it idiot proof and someone will make a better idiot.
=================================
Realise the impotence of proof reading everything you publish
Reply With Quote
  #5 (permalink)  
Old 02-18-09, 08:04 AM
DarleneMiles DarleneMiles is offline
Newbie Coder
 
Join Date: Jan 2009
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Thank you, you are too kind!
Reply With Quote
  #6 (permalink)  
Old 02-18-09, 08:25 AM
Yeroon's Avatar
Yeroon Yeroon is offline
Code Master
 
Join Date: Aug 2007
Location: Netherlands, Nijmegen
Posts: 850
Thanks: 2
Thanked 20 Times in 20 Posts
Code:
Workbooks.Open Filename:= _
"C:\Performance Template.xls", UpdateLinks:=0, ReadOnly:=True
Sheets(Array("LCData1", "Returns1")).Select
Sheets(Array("LCData1", "Returns1")).Copy before:=Workbooks(1).Sheets("BlankTab")
You can give an index for the workbook you need, starting with 1 being the first workbook. Does that help you with your problem?
__________________
Feel free to thank people if they help you by clicking thanks at a post.
=================================
Make it idiot proof and someone will make a better idiot.
=================================
Realise the impotence of proof reading everything you publish
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Need a little Macro Help LuckE13 Visual Basic 1 01-18-07 10:29 AM
Automated macro sujata_ghosh Visual Basic 1 12-08-06 09:01 AM
run macro excel with ASP page.. sal21 ASP 3 09-02-05 06:50 PM
Word Macro: Adding Rows to Locked Table gotham347 Visual Basic 0 01-07-05 09:09 PM


All times are GMT -5. The time now is 03:45 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.