Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default repeating a macro for a specified range

Hi

Im sure someone can help me with this. I have created an input box for
some data pasted in from another program. Some of these lines are
headers and page breaks which I want to remove , I have got an if
statement to flag each line with a Y if it needs deleting and for one
line I can use

If Range("L6") = "Y" Then

Range("E7:E28").Select
Range("E7:E28").Cut Destination:=Range("E6:E27")

End If

the next one would be

If Range("L7") = "Y" Then

Range("E8:E28").Select
Range("E8:E28").Cut Destination:=Range("E7:E27")


End If

etc


Is there a way of getting the macro to run automatically for all 20
lines, rather then just having 20 or so of the above

thanks in advance Will

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default repeating a macro for a specified range

If it is OK to delete the entire row, then

Sub ABC()
Dim i as Long, lastrow as Long
set lastrow = cells(rows.count,"L").End(xlup).row
for i = lastrow to 6 step -1
if cells(i,"L") = "Y" then
rows(i).Delete
end if
Next
end Sub

If just the cell in column E

Sub ABC()
Dim i as Long, lastrow as Long
set lastrow = cells(rows.count,"L").End(xlup).row
for i = lastrow to 6 step -1
if cells(i,"L") = "Y" then
cells(i,"E").Delete Shift:=xlShiftUp
end if
Next
end Sub


--
Regards,
Tom Ogilvy

"Willip" wrote in message
ups.com...
Hi

Im sure someone can help me with this. I have created an input box for
some data pasted in from another program. Some of these lines are
headers and page breaks which I want to remove , I have got an if
statement to flag each line with a Y if it needs deleting and for one
line I can use

If Range("L6") = "Y" Then

Range("E7:E28").Select
Range("E7:E28").Cut Destination:=Range("E6:E27")

End If

the next one would be

If Range("L7") = "Y" Then

Range("E8:E28").Select
Range("E8:E28").Cut Destination:=Range("E7:E27")


End If

etc


Is there a way of getting the macro to run automatically for all 20
lines, rather then just having 20 or so of the above

thanks in advance Will



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default repeating a macro for a specified range


Tom Ogilvy wrote:

If it is OK to delete the entire row, then

Sub ABC()
Dim i as Long, lastrow as Long
set lastrow = cells(rows.count,"L").End(xlup).row
for i = lastrow to 6 step -1
if cells(i,"L") = "Y" then
rows(i).Delete
end if
Next
end Sub

If just the cell in column E

Sub ABC()
Dim i as Long, lastrow as Long
set lastrow = cells(rows.count,"L").End(xlup).row
for i = lastrow to 6 step -1
if cells(i,"L") = "Y" then
cells(i,"E").Delete Shift:=xlShiftUp
end if
Next
end Sub


--
Regards,
Tom Ogilvy

"Willip" wrote in message
ups.com...
Hi

Im sure someone can help me with this. I have created an input box for
some data pasted in from another program. Some of these lines are
headers and page breaks which I want to remove , I have got an if
statement to flag each line with a Y if it needs deleting and for one
line I can use

If Range("L6") = "Y" Then

Range("E7:E28").Select
Range("E7:E28").Cut Destination:=Range("E6:E27")

End If

the next one would be

If Range("L7") = "Y" Then

Range("E8:E28").Select
Range("E8:E28").Cut Destination:=Range("E7:E27")


End If

etc


Is there a way of getting the macro to run automatically for all 20
lines, rather then just having 20 or so of the above

thanks in advance Will


That second one looks like what I'm after, I tried pasting it in, and
it gives a compile error, object required, with "lastrow =" highlighted
on the line set lastrow = cells(rows.count,"L").End(xlup).row

any ideas what I need to do to fix it?

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22,906
Default repeating a macro for a specified range

Remove the "Set" from the line to read..........

lastrow = Cells(Rows.Count, "L").End(xlUp).Row


Gord Dibben MS Excel MVP

On 24 Sep 2006 09:47:33 -0700, "Willip" wrote:


Tom Ogilvy wrote:

If it is OK to delete the entire row, then

Sub ABC()
Dim i as Long, lastrow as Long
set lastrow = cells(rows.count,"L").End(xlup).row
for i = lastrow to 6 step -1
if cells(i,"L") = "Y" then
rows(i).Delete
end if
Next
end Sub

If just the cell in column E

Sub ABC()
Dim i as Long, lastrow as Long
set lastrow = cells(rows.count,"L").End(xlup).row
for i = lastrow to 6 step -1
if cells(i,"L") = "Y" then
cells(i,"E").Delete Shift:=xlShiftUp
end if
Next
end Sub


--
Regards,
Tom Ogilvy

"Willip" wrote in message
ups.com...
Hi

Im sure someone can help me with this. I have created an input box for
some data pasted in from another program. Some of these lines are
headers and page breaks which I want to remove , I have got an if
statement to flag each line with a Y if it needs deleting and for one
line I can use

If Range("L6") = "Y" Then

Range("E7:E28").Select
Range("E7:E28").Cut Destination:=Range("E6:E27")

End If

the next one would be

If Range("L7") = "Y" Then

Range("E8:E28").Select
Range("E8:E28").Cut Destination:=Range("E7:E27")


End If

etc


Is there a way of getting the macro to run automatically for all 20
lines, rather then just having 20 or so of the above

thanks in advance Will


That second one looks like what I'm after, I tried pasting it in, and
it gives a compile error, object required, with "lastrow =" highlighted
on the line set lastrow = cells(rows.count,"L").End(xlup).row

any ideas what I need to do to fix it?


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
repeating macro dwake Excel Discussion (Misc queries) 2 December 1st 09 10:31 PM
Repeating Macro Dino Excel Discussion (Misc queries) 3 February 15th 06 03:58 AM
Repeating macro with dynamic range [email protected] Excel Programming 1 September 30th 05 07:11 PM
How do I check repeating sets of number in a range Tshidiso Excel Worksheet Functions 1 September 2nd 05 11:02 AM
Repeating macro Michael[_24_] Excel Programming 3 December 5th 03 08:32 PM


All times are GMT +1. The time now is 10:15 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"