Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 72
Default Help with this marco

Sub DeleteSemester()
Range("N1:AR100").Cut Cells(305, "N")
Dim lr As Long, x As Long
lr = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row
x = lr - 5
ActiveSheet.Rows(x & ":" & lr - 1).Delete
Range("N300:AR400").Cut Cells(1, "N")
End Sub

How can I make this marco so that if the last row in columns A:M is row 6 or
less it does not run.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 141
Default Help with this marco

Hello, Try this

Sub DeleteSemester()
Dim i As Integer
Dim cell As Range
i = 1
For Each cell In Range("A65536:M65536")
If cell.End(xlUp).Row i Then i = cell.End(xlUp).Row
Next cell
If i <= 6 Then Exit Sub
Range("N1:AR100").Cut Cells(305, "N")
Dim lr As Long, x As Long
lr = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row
x = lr - 5
ActiveSheet.Rows(x & ":" & lr - 1).Delete
Range("N300:AR400").Cut Cells(1, "N")
End Sub
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Help with this marco

Maybe

Sub nn()
For cols = 1 To 13
Cells(1, cols).Select
If ActiveSheet.Cells(Rows.Count, cols).End(xlUp).Row < 6 Then
Exit Sub
Else
' Your code
End If
Next
End Sub

Mike

"JBoyer" wrote:

Sub DeleteSemester()
Range("N1:AR100").Cut Cells(305, "N")
Dim lr As Long, x As Long
lr = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row
x = lr - 5
ActiveSheet.Rows(x & ":" & lr - 1).Delete
Range("N300:AR400").Cut Cells(1, "N")
End Sub

How can I make this marco so that if the last row in columns A:M is row 6 or
less it does not run.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Help with this marco

Try it this way (notice I reduced your middle 4 lines down to a single line
of code)...

Sub DeleteSemester()
With ActiveSheet
If Application.WorksheetFunction.CountA( _
.Range("A7:M" & Rows.Count)) = 0 Then
.Range("N1:AR100").Cut .Cells(305, "N")
.Cells(Rows.Count, 1).End(xlUp).EntireRow.Offset(-5).Resize(5).Delete
.Range("N300:AR400").Cut .Cells(1, "N")
End If
End With
End Sub

Rick


"JBoyer" wrote in message
...
Sub DeleteSemester()
Range("N1:AR100").Cut Cells(305, "N")
Dim lr As Long, x As Long
lr = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row
x = lr - 5
ActiveSheet.Rows(x & ":" & lr - 1).Delete
Range("N300:AR400").Cut Cells(1, "N")
End Sub

How can I make this marco so that if the last row in columns A:M is row 6
or
less it does not run.


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 72
Default Help with this marco

All the replies look good guys, thanks for the help. I tried Rick's first,
but I failed to explain one of my cateria, and his being the simplest code
didn't cover my criteria. Not his fault though, my fault for not explaining.
Luckily though after rereading the replies I found that GTVT covered what I
need, so it is what I am currently using. Anyway thanks for all your help
guys, including you Mike, who I didn't mention.

"GTVT06" wrote:

Hello, Try this

Sub DeleteSemester()
Dim i As Integer
Dim cell As Range
i = 1
For Each cell In Range("A65536:M65536")
If cell.End(xlUp).Row i Then i = cell.End(xlUp).Row
Next cell
If i <= 6 Then Exit Sub
Range("N1:AR100").Cut Cells(305, "N")
Dim lr As Long, x As Long
lr = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row
x = lr - 5
ActiveSheet.Rows(x & ":" & lr - 1).Delete
Range("N300:AR400").Cut Cells(1, "N")
End Sub

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
Marco JBoyer Excel Programming 3 July 8th 08 10:49 PM
Marco Help LaDdIe Excel Programming 2 July 16th 07 09:44 PM
Marco Help looper Excel Discussion (Misc queries) 2 May 12th 07 06:55 PM
marco help mr1104839 Excel Programming 2 August 17th 06 05:42 PM
help me with this marco Gary Keramidas Excel Programming 1 April 22nd 06 02:01 AM


All times are GMT +1. The time now is 04:16 PM.

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

About Us

"It's about Microsoft Excel"