Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 117
Default variable range: l just can't get there!

Hello to all, this is the scenario: l have 60 sheets in a workbook, 56
of them are named S1, S2, S3 etc etc up to S56, what l want to do is
check a range on each sheet for any blank cells, my problem is that
the range changes on each sheet... this is what l have so far (some
code borrowed from a post by Nick Hodge, thanks Nick)...the start
address of the range will be the same on each sheet which is "A3" the
end of the range will be the last used cell in col AS..
this is where l am beat... the last cell in col AS changes on each
sheet...
it would be nice if it did find any cell with lost data to tell me
what the cell address was, as some of these sheets carry a lot of
data...

Thans for any help....seeya ste

Public Sub checkforlostdata()

Dim myCell As Range
Dim endofrange As Variant

For sheetnumber = 1 To 2

sheetname = "S" & Format(sheetnumber, "##0")
Sheets(sheetname).Select


ActiveSheet.Range("AS1").End(xlDown).Select
ActiveCell.cell.Address = endofrange

For Each myCell In ActiveSheet.Range("A3:endofrange")
If IsEmpty(myCell.Value) Then
MsgBox "There is lost data on sheet " & sheetname
Cancel = True
Exit Sub
End If
Next myCell
Next
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default variable range: l just can't get there!

Public Sub checkforlostdata()

Dim myCell As Range
Dim endofrange As Variant

For sheetnumber = 1 To 2

sheetname = "S" & Format(sheetnumber, "##0")
Sheets(sheetname).Select


ActiveSheet.Range("AS1").End(xlDown).Select
endofrange = ActiveCell.cell.Address '<==

For Each myCell In ActiveSheet.Range("A3:" & endofrange) ' <==
If IsEmpty(myCell.Value) Then
MsgBox "There is lost data on sheet " & sheetname
Cancel = True
Exit Sub
End If
Next myCell
Next
End Sub


A possibility (which should be faster


Dim sh As Worksheet, rng As Range, rng1 As Range
For Each sh In ThisWorkbook.Worksheets
If Left(sh.Name, 1) = "S" And _
IsNumeric(Right(sh.Name, Len(sh.Name) - 1)) Then
Set rng = sh.Range(sh.Cells(1, 1), _
sh.Cells(Rows.Count, "AS").End(xlUp))
On Error Resume Next
Set rng1 = rng.SpecialCells(xlBlanks)
On Error GoTo 0
If Not rng1 Is Nothing Then
MsgBox "There is lost data on sheet " _
& sh.Name
'Exit Sub
End If
End If
Next



or
Dim sh as Worksheet, rng as Range, rng1 as Range
Dim sStr as String
sStr = "There is lost data on sheets: " & vbNewLine
For each sh in Thisworkbook.Worksheets
if Left(sh.name,1)="S" and isnumeric(right(sh.name,len(sh.name)-1)) then
set rng = sh.Range(sh.Cells(1,1),sh.Cells(rows.count,"AS").E nd(xlup))
on Error Resume Next
set rng1 = rng.SpecialCells(xlBlanks)
on Error Goto 0
if not rng1 is nothing then
sStr = sStr & sh.Name & "," & vbNewLine
end if
End if
Next
MsgBox sStr

Code is untested and may contain typos, but should give you a general idea.

--
Regards,
Tom Ogilvy

"ste mac" wrote in message
om...
Hello to all, this is the scenario: l have 60 sheets in a workbook, 56
of them are named S1, S2, S3 etc etc up to S56, what l want to do is
check a range on each sheet for any blank cells, my problem is that
the range changes on each sheet... this is what l have so far (some
code borrowed from a post by Nick Hodge, thanks Nick)...the start
address of the range will be the same on each sheet which is "A3" the
end of the range will be the last used cell in col AS..
this is where l am beat... the last cell in col AS changes on each
sheet...
it would be nice if it did find any cell with lost data to tell me
what the cell address was, as some of these sheets carry a lot of
data...

Thans for any help....seeya ste

Public Sub checkforlostdata()

Dim myCell As Range
Dim endofrange As Variant

For sheetnumber = 1 To 2

sheetname = "S" & Format(sheetnumber, "##0")
Sheets(sheetname).Select


ActiveSheet.Range("AS1").End(xlDown).Select
ActiveCell.cell.Address = endofrange

For Each myCell In ActiveSheet.Range("A3:endofrange")
If IsEmpty(myCell.Value) Then
MsgBox "There is lost data on sheet " & sheetname
Cancel = True
Exit Sub
End If
Next myCell
Next
End Sub



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 117
Default variable range: l just can't get there!

Thanks a lot Tom, and so quick too! it did the trick no-problem..

once again thanks for your help...

seeya ste




"Tom Ogilvy" wrote in message ...
Public Sub checkforlostdata()

Dim myCell As Range
Dim endofrange As Variant

For sheetnumber = 1 To 2

sheetname = "S" & Format(sheetnumber, "##0")
Sheets(sheetname).Select


ActiveSheet.Range("AS1").End(xlDown).Select
endofrange = ActiveCell.cell.Address '<==

For Each myCell In ActiveSheet.Range("A3:" & endofrange) ' <==
If IsEmpty(myCell.Value) Then
MsgBox "There is lost data on sheet " & sheetname
Cancel = True
Exit Sub
End If
Next myCell
Next
End Sub


A possibility (which should be faster


Dim sh As Worksheet, rng As Range, rng1 As Range
For Each sh In ThisWorkbook.Worksheets
If Left(sh.Name, 1) = "S" And _
IsNumeric(Right(sh.Name, Len(sh.Name) - 1)) Then
Set rng = sh.Range(sh.Cells(1, 1), _
sh.Cells(Rows.Count, "AS").End(xlUp))
On Error Resume Next
Set rng1 = rng.SpecialCells(xlBlanks)
On Error GoTo 0
If Not rng1 Is Nothing Then
MsgBox "There is lost data on sheet " _
& sh.Name
'Exit Sub
End If
End If
Next



or
Dim sh as Worksheet, rng as Range, rng1 as Range
Dim sStr as String
sStr = "There is lost data on sheets: " & vbNewLine
For each sh in Thisworkbook.Worksheets
if Left(sh.name,1)="S" and isnumeric(right(sh.name,len(sh.name)-1)) then
set rng = sh.Range(sh.Cells(1,1),sh.Cells(rows.count,"AS").E nd(xlup))
on Error Resume Next
set rng1 = rng.SpecialCells(xlBlanks)
on Error Goto 0
if not rng1 is nothing then
sStr = sStr & sh.Name & "," & vbNewLine
end if
End if
Next
MsgBox sStr

Code is untested and may contain typos, but should give you a general idea.

--
Regards,
Tom Ogilvy

"ste mac" wrote in message
om...
Hello to all, this is the scenario: l have 60 sheets in a workbook, 56
of them are named S1, S2, S3 etc etc up to S56, what l want to do is
check a range on each sheet for any blank cells, my problem is that
the range changes on each sheet... this is what l have so far (some
code borrowed from a post by Nick Hodge, thanks Nick)...the start
address of the range will be the same on each sheet which is "A3" the
end of the range will be the last used cell in col AS..
this is where l am beat... the last cell in col AS changes on each
sheet...
it would be nice if it did find any cell with lost data to tell me
what the cell address was, as some of these sheets carry a lot of
data...

Thans for any help....seeya ste

Public Sub checkforlostdata()

Dim myCell As Range
Dim endofrange As Variant

For sheetnumber = 1 To 2

sheetname = "S" & Format(sheetnumber, "##0")
Sheets(sheetname).Select


ActiveSheet.Range("AS1").End(xlDown).Select
ActiveCell.cell.Address = endofrange

For Each myCell In ActiveSheet.Range("A3:endofrange")
If IsEmpty(myCell.Value) Then
MsgBox "There is lost data on sheet " & sheetname
Cancel = True
Exit Sub
End If
Next myCell
Next
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
Variable Range for NPV Dkline Excel Worksheet Functions 7 August 27th 08 02:14 PM
how to specify a range that is variable. Mal[_2_] Excel Worksheet Functions 4 April 9th 08 03:39 PM
variable range John New Users to Excel 2 July 21st 06 03:42 PM
Variable in Range aftamath Excel Discussion (Misc queries) 2 October 6th 05 07:48 PM
Problem trying to us a range variable as an array variable TBA[_2_] Excel Programming 4 September 27th 03 02:56 PM


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

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"