Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Rob Rob is offline
external usenet poster
 
Posts: 718
Default Looping code

Hi,

The code below checks data in a row and depending on the outcome will
display a User Form. If the data in the row does not meet the criteria to
show the User Form then a cell in the row below is activated. If the User
Form is displayed (because the data has met the criteria) then, on closing it
as previously mentioned a cell in the row below is activated.

Sub CheckVolumeRise()
If ActiveCell <ActiveCell.Offset(0, 2) And _
ActiveCell.Offset(0, 2) < ActiveCell.Offset(0, 4) Then
Selection.End(xlToLeft).Select
CriteriaReached.Show
Selection.End(xlToRight).Select
ActiveCell.Offset(1, -4).Activate
Else
ActiveCell.Offset(1, 0).Activate
End If
End Sub

Please will someone show me how to loop this code down through the rows
until an empty row is reached.

Thank you.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 99
Default Looping code

On Mar 17, 8:51*am, Rob wrote:
Hi,

The code below checks data in a row and depending on the outcome will
display a User Form. If the data in the row does not meet the criteria to
show the User Form then a cell in the row below is activated. If the User
Form is displayed (because the data has met the criteria) then, on closing it
as previously mentioned *a cell in the row below is activated.

Sub CheckVolumeRise()
If ActiveCell <ActiveCell.Offset(0, 2) And *_
ActiveCell.Offset(0, 2) < *ActiveCell.Offset(0, 4) Then
Selection.End(xlToLeft).Select
CriteriaReached.Show
Selection.End(xlToRight).Select
ActiveCell.Offset(1, -4).Activate
Else
ActiveCell.Offset(1, 0).Activate
End If
End Sub

Please will someone show me how to loop this code down through the row’s
until an empty row is reached.

Thank you.

I have modified the code as follows
Try this out.
Sub Chkrise()
Dim nosofrows As Long
start:
If ActiveCell < ActiveCell.Offset(0, 2) And _
ActiveCell.Offset(0, 2) < ActiveCell.Offset(0, 4) Then
Selection.End(xlToLeft).Select
criteriaReached.Show
'Selection.End(xlToRight).Select (not considered necessary so omitted)
'ActiveCell.Offset(1, -4).Activate (not considered necessary so
omitted)
Else
ActiveCell.Offset(1, 0).Activate
nosofrows = ActiveSheet.UsedRange.Rows.Count + _
ActiveSheet.UsedRange.Row - 1 'this gives the last rows that is used
If ActiveCell.Row < nosofrows Then GoTo start
End If
'ActiveSheet.Cells.SpecialCells(xlCellTypeLastCell ).Activate

End Sub
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,510
Default Looping code

Hi Rob,

Not really sure that I understand the question correctly.
I interpretted as the loop to be after the form is closed. Is this correct?
When you say empty row, do you mean the entire row because that is how I
interpreted?

CountA counts the number of cells that are NOT empty in the row therefore if
it returns zero then the row is empty.


Sub CheckVolumeRise()
Dim lngCol As Long
Dim lngRow As Long

If ActiveCell < ActiveCell.Offset(0, 2) And _
ActiveCell.Offset(0, 2) < ActiveCell.Offset(0, 4) Then

Selection.End(xlToLeft).Select

CriteriaReached.Show

'following code will not run until
'after the form is closed.
Selection.End(xlToRight).Select
ActiveCell.Offset(1, -4).Activate

lngCol = ActiveCell.Column

For lngRow = ActiveCell.Row To Rows.Count
If WorksheetFunction.CountA _
(Cells(lngRow, lngCol).EntireRow) = 0 Then

MsgBox "Row " & lngRow & " Is empty."
Exit For 'Don't go any further
End If
Next lngRow
Else
ActiveCell.Offset(1, 0).Activate
End If
End Sub

--
Regards,

OssieMac


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,510
Default Looping code

I have found that UsedRange is a very unreliable method of finding the last
row. If the cells below the last data cells are formatted then usedrange can
include them even though they have no data. Also, if you enter data in any
cells below the normal data range and then clear those cells then usedrange
can include the cleared cells.

--
Regards,

OssieMac


"Subodh" wrote:

On Mar 17, 8:51 am, Rob wrote:
Hi,

The code below checks data in a row and depending on the outcome will
display a User Form. If the data in the row does not meet the criteria to
show the User Form then a cell in the row below is activated. If the User
Form is displayed (because the data has met the criteria) then, on closing it
as previously mentioned a cell in the row below is activated.

Sub CheckVolumeRise()
If ActiveCell <ActiveCell.Offset(0, 2) And _
ActiveCell.Offset(0, 2) < ActiveCell.Offset(0, 4) Then
Selection.End(xlToLeft).Select
CriteriaReached.Show
Selection.End(xlToRight).Select
ActiveCell.Offset(1, -4).Activate
Else
ActiveCell.Offset(1, 0).Activate
End If
End Sub

Please will someone show me how to loop this code down through the rows
until an empty row is reached.

Thank you.

I have modified the code as follows
Try this out.
Sub Chkrise()
Dim nosofrows As Long
start:
If ActiveCell < ActiveCell.Offset(0, 2) And _
ActiveCell.Offset(0, 2) < ActiveCell.Offset(0, 4) Then
Selection.End(xlToLeft).Select
criteriaReached.Show
'Selection.End(xlToRight).Select (not considered necessary so omitted)
'ActiveCell.Offset(1, -4).Activate (not considered necessary so
omitted)
Else
ActiveCell.Offset(1, 0).Activate
nosofrows = ActiveSheet.UsedRange.Rows.Count + _
ActiveSheet.UsedRange.Row - 1 'this gives the last rows that is used
If ActiveCell.Row < nosofrows Then GoTo start
End If
'ActiveSheet.Cells.SpecialCells(xlCellTypeLastCell ).Activate

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
Looping Code tpeter Excel Programming 5 October 16th 09 08:26 PM
looping code Ksenija Excel Programming 1 January 23rd 09 04:05 PM
Looping rather than code for each row Martin Excel Programming 11 September 9th 08 03:10 PM
Help with Looping Code JimMay Excel Programming 5 June 6th 06 03:43 AM
Code looping when it should not Todd Huttenstine Excel Programming 3 May 13th 04 09:37 PM


All times are GMT +1. The time now is 01:56 AM.

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"