Welcome to Tech Support Forum home to more then 136,000 problems solved. Issues have included: Spyware, Malware, Virus Issues, Windows, Microsoft, Linux, Networking, Security, Hardware, and Gaming Getting your problem solved is as easy as:
1. Registering for a free account
2. Asking your question
3. Receiving an answer

Registered members:
* Get free support
* Communicate privately with other members (PM).
* Removal of this message
* See fewer ads.
* And much more..

 



Want to know how to post a question? click here Having problems with spyware and pop-ups? First Steps
Go Back   Tech Support Forum > Microsoft Support > Microsoft Office support
User Name
Password
Site Map Register Donate Rules Blogs Mark Forums Read


Microsoft Office support MS Office support forum

Reply
 
LinkBack Thread Tools
Old 08-05-2008, 09:54 AM   #1 (permalink)
Registered User
 
Join Date: Jun 2008
Posts: 6
OS: xp


Post Macro Adjusted

I need a macro that searches Column L in the worksheet "CurrentOnlineStatements" for the word remove,
then cuts that row and pastes it in the next worksheet called "DeletedOnlineStatements"

But instead of pasting it in row 100, I need it to look for the next available empty row.

I also need it continue to search and not stop at the first row found.

Dim sc As Range
Dim foundrow As Long

For Each sc In Sheets("CurrentOnlineStatements").Range("L:L")
If sc.Value = "Remove" Then
foundrow = sc.Row
Exit For
End If
Next sc

If foundrow > 0 Then
Sheets("CurrentOnlineStatements").Rows(foundrow).Cut Sheets("DeletedOnlineStatements").Rows(100)
Sheets("CurrentOnlineStatements").Rows(foundrow).Delete xlUp
End If

Any Help would be great. Thanks sparker
stephparker is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Important Information
Join the #1 Tech Support Forum Today - It's Totally Free!

TechSupportForum.com is a leading support website for your computer needs. We offer free, friendly and personalized computer support. Why pay to have your computer fixed when you can do it for free.

Join TechSupportforum.com Today - Click Here

Old 08-05-2008, 12:49 PM   #2 (permalink)
Registered User
 
Join Date: May 2008
Location: Baltimore, Maryland
Posts: 160
OS: Windows XP SP3


Re: Macro Adjusted

Here's one way to do it.

Code:
Sub remove()
    Dim sr As Long
    Dim tr As Long
    Dim cp() As Byte
    ReDim cp(Sheets("CurrentOnlineStatements").Range("L:L").Rows.Count) As Byte

    For sr = 1 To Sheets("CurrentOnlineStatements").Range("L:L").Rows.Count
        If LCase(Sheets("CurrentOnlineStatements").Cells(sr, 12).Value) = "remove" Then
            For tr = 1 To Sheets("DeletedOnlineStatements").Range("L:L").Rows.Count
                If WorksheetFunction.CountA(Sheets("DeletedOnlineStatements").Rows(tr).EntireRow) = 0 Then
                    Sheets("CurrentOnlineStatements").Rows(sr).Copy Sheets("DeletedOnlineStatements").Rows(tr)
                    cp(sr) = 1
                    Exit For
                End If
            Next tr
        End If
    Next sr

    For sr = Sheets("CurrentOnlineStatements").Range("L:L").Rows.Count To 1 Step -1
        If cp(sr) = 1 Then
            Sheets("CurrentOnlineStatements").Rows(sr).EntireRow.Delete
        End If
    Next sr
End Sub
Modify as necessary.
David M58 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Old 08-06-2008, 07:34 AM   #3 (permalink)
Registered User
 
Join Date: Jun 2008
Posts: 6
OS: xp


Re: Macro Adjusted

Thank you! Thank you! Thank you! Thank you! Thank you! Thank you! Thank you! Thank you! It works perfectly! It will save us tons of time.
stephparker is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Old 08-06-2008, 12:48 PM   #4 (permalink)
Registered User
 
Join Date: Jun 2008
Posts: 6
OS: xp


Re: Macro Adjusted

I want to use the macro you gave me for another spreadsheet. I have made the adjustments for the different criteria. But I want to ask it to identify criteria 12 diffrent times and put each a different tab. I tried to use this macro more than once by renaming it. But it doesn't work if I rename the macro. Any suggestions?

Sub remove()
Dim sr As Long
Dim tr As Long
Dim cp() As Byte
ReDim cp(Sheets("CD").Range("B:B").Rows.Count) As Byte

For sr = 1 To Sheets("CD").Range("B:B").Rows.Count
If LCase(Sheets("CD").Cells(sr, 2).Value) = "Glenstone" Then
For tr = 1 To Sheets("Glenstone").Range("B:B").Rows.Count
If WorksheetFunction.CountA(Sheets("Glenstone").Rows(tr).EntireRow) = 0 Then
Sheets("CD").Rows(sr).Copy Sheets("Glenstone").Rows(tr)
cp(sr) = 1
Exit For
End If
Next tr
End If
Next sr

For sr = Sheets("CD").Range("B:B").Rows.Count To 1 Step -1
If cp(sr) = 1 Then
Sheets("CD").Rows(sr).EntireRow.delete
End If
Next sr
End Sub
stephparker is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Old 08-06-2008, 03:19 PM   #5 (permalink)
Registered User
 
Join Date: May 2008
Location: Baltimore, Maryland
Posts: 160
OS: Windows XP SP3


Re: Macro Adjusted

There is a problem with one of the lines of code you posted:

If LCase(Sheets("CD").Cells(sr, 2).Value) = "Glenstone" Then
The problem is that the word "Glenstone" has a capital letter, but it is being compared to lowercase text with the LCase function, causing it to fail.

You can modify the line to read:

If LCase(Sheets("CD").Cells(sr, 2).Value) = "glenstone" Then
for a search that is not case-sensitive, or:

If Sheets("CD").Cells(sr, 2).Value = "Glenstone" Then
if you want a case-sensitive search.

Last edited by David M58; 08-06-2008 at 03:22 PM.
David M58 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Old 08-07-2008, 08:18 AM   #6 (permalink)
Registered User
 
Join Date: Jun 2008
Posts: 6
OS: xp


Re: Macro Adjusted

Thank you. I have it working for all my criteria with a few bugs I am still working out. You have been a great help!!! Thank sparker
stephparker is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Reply


Thread Tools

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 On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




All times are GMT -7. The time now is 01:34 PM.



Copyright 2001 - 2009, Tech Support Forum
Home Tips Plus | Outdoor Basecamp | Automotive Support Forum

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85