Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 573
Default Object variable or withblock variable not set

Wrote this:

Sub CountReasonContactCode()
Dim Wksht As Worksheet
Dim rReason As Range
Dim lRow As Long
Dim lCurRow As Long
Dim rCell As Range
Dim l16Rct As Long
Dim l16Act As Long
Dim l16BGct As Long
Dim lCt As Long
Dim lTotNameRow As Long

lRow = 107
lTotNameRow = 4
l16Rct = 0
l16Act = 0
l16BGct = 0


Do Until Wksht.Name = "Totals" <---Object Variable or Withblock
variable not set
For Each Wksht In ThisWorkbook.Worksheets

I tried setting wksht = to activeworkbook.worksheets, but that gave me
another error. Any suggestions?
Thanks again!

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Object variable or withblock variable not set

Hi Dave,

Do Until Wksht.Name = "Totals" <---Object Variable or Withblock
variable not set
For Each Wksht In ThisWorkbook.Worksheets


If your intention is to operate on all worksheets except the Totals sheet,
try:

For Each Wksht In ThisWorkbook.Worksheets
If Wksht.Name < "Totals" Then
' your processing code
End If
Next Wksht

If, alternatively, your intention is to stop processing when the iteration
reaches the Totals sheet, try:

For Each Wksht In ThisWorkbook.Worksheets
If Wksht.Name = "Totals" Then Exit For
' Your processing code
Next Wksht

---
Regards,
Norman



"davegb" wrote in message
ups.com...
Wrote this:

Sub CountReasonContactCode()
Dim Wksht As Worksheet
Dim rReason As Range
Dim lRow As Long
Dim lCurRow As Long
Dim rCell As Range
Dim l16Rct As Long
Dim l16Act As Long
Dim l16BGct As Long
Dim lCt As Long
Dim lTotNameRow As Long

lRow = 107
lTotNameRow = 4
l16Rct = 0
l16Act = 0
l16BGct = 0


Do Until Wksht.Name = "Totals" <---Object Variable or Withblock
variable not set
For Each Wksht In ThisWorkbook.Worksheets

I tried setting wksht = to activeworkbook.worksheets, but that gave me
another error. Any suggestions?
Thanks again!



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 414
Default Object variable or withblock variable not set

Hi Dave

Try it like this:


For Each Wksht In ThisWorkbook.Worksheets
if Wksht.Name = "Totals" then
'do something
else
'do something else
end if
next Wksht

Hope this helps
Rowan

davegb wrote:
Wrote this:

Sub CountReasonContactCode()
Dim Wksht As Worksheet
Dim rReason As Range
Dim lRow As Long
Dim lCurRow As Long
Dim rCell As Range
Dim l16Rct As Long
Dim l16Act As Long
Dim l16BGct As Long
Dim lCt As Long
Dim lTotNameRow As Long

lRow = 107
lTotNameRow = 4
l16Rct = 0
l16Act = 0
l16BGct = 0


Do Until Wksht.Name = "Totals" <---Object Variable or Withblock
variable not set
For Each Wksht In ThisWorkbook.Worksheets

I tried setting wksht = to activeworkbook.worksheets, but that gave me
another error. Any suggestions?
Thanks again!

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 573
Default Object variable or withblock variable not set


Norman Jones wrote:
Hi Dave,

Do Until Wksht.Name = "Totals" <---Object Variable or Withblock
variable not set
For Each Wksht In ThisWorkbook.Worksheets


If your intention is to operate on all worksheets except the Totals sheet,
try:

For Each Wksht In ThisWorkbook.Worksheets
If Wksht.Name < "Totals" Then
' your processing code
End If
Next Wksht

If, alternatively, your intention is to stop processing when the iteration
reaches the Totals sheet, try:

For Each Wksht In ThisWorkbook.Worksheets
If Wksht.Name = "Totals" Then Exit For
' Your processing code
Next Wksht

---
Regards,
Norman



"davegb" wrote in message
ups.com...
Wrote this:

Sub CountReasonContactCode()
Dim Wksht As Worksheet
Dim rReason As Range
Dim lRow As Long
Dim lCurRow As Long
Dim rCell As Range
Dim l16Rct As Long
Dim l16Act As Long
Dim l16BGct As Long
Dim lCt As Long
Dim lTotNameRow As Long

lRow = 107
lTotNameRow = 4
l16Rct = 0
l16Act = 0
l16BGct = 0


Do Until Wksht.Name = "Totals" <---Object Variable or Withblock
variable not set
For Each Wksht In ThisWorkbook.Worksheets

I tried setting wksht = to activeworkbook.worksheets, but that gave me
another error. Any suggestions?
Thanks again!


Thanks to all of you for your help. I should have mentioned that there
are other sheets in the workbook I don't want the macro to do. I just
want it to do the ones to the left of Totals, not the ones to the
right. So I used the second variation you suggested, Norman. Works fine!

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
Runtime Error '91' Object variable or With block variable not set Alec Coliver Excel Discussion (Misc queries) 2 October 24th 09 02:29 PM
Run-time Error'91: Object variable or With block variable not set DynamiteSkippy Excel Programming 4 September 26th 05 07:47 AM
Run-time error '91': "Object variable or With block variable not set Mike[_92_] Excel Programming 2 December 30th 04 10:59 AM
Cells.Find error Object variable or With block variable not set Peter[_21_] Excel Programming 2 May 8th 04 02:15 PM
Pivot Table - Object variable or with block variable not set? George Nicholson[_2_] Excel Programming 1 April 16th 04 09:12 PM


All times are GMT +1. The time now is 05:40 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"