![]() |
![]() |
![]() |
|||||
![]() |
![]() |
![]() |
![]() |
![]() |
|||
| 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: * 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 |
|
|||||||
| Microsoft Office support MS Office support forum |
![]() |
|
|
LinkBack | Thread Tools |
|
|
#1 (permalink) |
|
Registered User
Join Date: Jun 2008
Posts: 6
OS: xp
|
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 |
|
|
|
| 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 |
|
|
#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
|
|
|
|
|
|
#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 |
|
|
|
|
|
#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" ThenThe 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" Thenfor a search that is not case-sensitive, or: If Sheets("CD").Cells(sr, 2).Value = "Glenstone" Thenif you want a case-sensitive search. Last edited by David M58; 08-06-2008 at 03:22 PM. |
|
|
|
![]() |
| Thread Tools | |
|
|