Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 271
Default Loop problem

Here is my code (it is the beginning of something that will be longer):

Sub ByQuestion()

ByQuestionReport.InitializeDeclerations

Dim BQStart As Range
Set BQStart = ThisWorkbook.Names("BQStart").RefersToRange

If WSCri.Range("C28").Value = "Provider" Then

BQStart.Select

Do Until BQStart.Value = ""

If ActiveCell = 1 Then

' ActiveCell.Offset(-1, 0).Copy
' ActiveCell.PasteSpecial (xlPasteValues)

End If

BQStart.Offset(0, 1).Select
Set BQStart = ActiveCell

Loop

End If

End Sub

The problem is that the code loops fine until it gets to a cell with a value
in it of #DIV/0! When it hits such a cell I get a type mismatch error???


--
Thanks
Shawn
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,119
Default Loop problem

Since you have a range object I would avoid tha active cell thing. As fo rthe
error you have a couple of choices. On Error Resume Next / On Error Goto 0 or
(in my opinion a better way to go change the formula to avoid creating the
error.

If(Denominator cell = 0, 0, Perform division)

Option 1
Sub ByQuestion()

ByQuestionReport.InitializeDeclerations

Dim BQStart As Range
Set BQStart = ThisWorkbook.Names("BQStart").RefersToRange

If WSCri.Range("C28").Value = "Provider" Then
On Error Resume Next
Do Until BQStart.Value = ""

If BQStart.value = 1 Then

BQStart.Offset(-1, 0).Copy
BQStart.PasteSpecial (xlPasteValues)

End If

Set BQStart = BQStart.offest(0,1)

Loop
On Error Goto Zero
End If

End Sub

--
HTH...

Jim Thomlinson


"Shawn" wrote:

Here is my code (it is the beginning of something that will be longer):

Sub ByQuestion()

ByQuestionReport.InitializeDeclerations

Dim BQStart As Range
Set BQStart = ThisWorkbook.Names("BQStart").RefersToRange

If WSCri.Range("C28").Value = "Provider" Then

BQStart.Select

Do Until BQStart.Value = ""

If ActiveCell = 1 Then

' ActiveCell.Offset(-1, 0).Copy
' ActiveCell.PasteSpecial (xlPasteValues)

End If

BQStart.Offset(0, 1).Select
Set BQStart = ActiveCell

Loop

End If

End Sub

The problem is that the code loops fine until it gets to a cell with a value
in it of #DIV/0! When it hits such a cell I get a type mismatch error???


--
Thanks
Shawn

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 271
Default Loop problem

I copied and pasted your code over mine. When the code gets to the On Error
Goto 0 it says there is no label or something?
--
Thanks
Shawn


"Jim Thomlinson" wrote:

Since you have a range object I would avoid tha active cell thing. As fo rthe
error you have a couple of choices. On Error Resume Next / On Error Goto 0 or
(in my opinion a better way to go change the formula to avoid creating the
error.

If(Denominator cell = 0, 0, Perform division)

Option 1
Sub ByQuestion()

ByQuestionReport.InitializeDeclerations

Dim BQStart As Range
Set BQStart = ThisWorkbook.Names("BQStart").RefersToRange

If WSCri.Range("C28").Value = "Provider" Then
On Error Resume Next
Do Until BQStart.Value = ""

If BQStart.value = 1 Then

BQStart.Offset(-1, 0).Copy
BQStart.PasteSpecial (xlPasteValues)

End If

Set BQStart = BQStart.offest(0,1)

Loop
On Error Goto Zero
End If

End Sub

--
HTH...

Jim Thomlinson


"Shawn" wrote:

Here is my code (it is the beginning of something that will be longer):

Sub ByQuestion()

ByQuestionReport.InitializeDeclerations

Dim BQStart As Range
Set BQStart = ThisWorkbook.Names("BQStart").RefersToRange

If WSCri.Range("C28").Value = "Provider" Then

BQStart.Select

Do Until BQStart.Value = ""

If ActiveCell = 1 Then

' ActiveCell.Offset(-1, 0).Copy
' ActiveCell.PasteSpecial (xlPasteValues)

End If

BQStart.Offset(0, 1).Select
Set BQStart = ActiveCell

Loop

End If

End Sub

The problem is that the code loops fine until it gets to a cell with a value
in it of #DIV/0! When it hits such a cell I get a type mismatch error???


--
Thanks
Shawn

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,119
Default Loop problem

I typed in the word zero by accident. I have been doing documentation all day
and actual numbers are just not working out for me.. it shoud be

Sub Your Sub()
On Error Resume Next
'your loop
On Error GoTo 0
End Sub

My appologies...
--
HTH...

Jim Thomlinson


"Shawn" wrote:

I copied and pasted your code over mine. When the code gets to the On Error
Goto 0 it says there is no label or something?
--
Thanks
Shawn


"Jim Thomlinson" wrote:

Since you have a range object I would avoid tha active cell thing. As fo rthe
error you have a couple of choices. On Error Resume Next / On Error Goto 0 or
(in my opinion a better way to go change the formula to avoid creating the
error.

If(Denominator cell = 0, 0, Perform division)

Option 1
Sub ByQuestion()

ByQuestionReport.InitializeDeclerations

Dim BQStart As Range
Set BQStart = ThisWorkbook.Names("BQStart").RefersToRange

If WSCri.Range("C28").Value = "Provider" Then
On Error Resume Next
Do Until BQStart.Value = ""

If BQStart.value = 1 Then

BQStart.Offset(-1, 0).Copy
BQStart.PasteSpecial (xlPasteValues)

End If

Set BQStart = BQStart.offest(0,1)

Loop
On Error Goto Zero
End If

End Sub

--
HTH...

Jim Thomlinson


"Shawn" wrote:

Here is my code (it is the beginning of something that will be longer):

Sub ByQuestion()

ByQuestionReport.InitializeDeclerations

Dim BQStart As Range
Set BQStart = ThisWorkbook.Names("BQStart").RefersToRange

If WSCri.Range("C28").Value = "Provider" Then

BQStart.Select

Do Until BQStart.Value = ""

If ActiveCell = 1 Then

' ActiveCell.Offset(-1, 0).Copy
' ActiveCell.PasteSpecial (xlPasteValues)

End If

BQStart.Offset(0, 1).Select
Set BQStart = ActiveCell

Loop

End If

End Sub

The problem is that the code loops fine until it gets to a cell with a value
in it of #DIV/0! When it hits such a cell I get a type mismatch error???


--
Thanks
Shawn

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
Problem adding charts using Do-Loop Until loop Chris Bromley[_2_] Excel Programming 2 May 23rd 05 01:31 PM
Loop Problem John[_88_] Excel Programming 3 July 10th 04 10:55 AM
Loop Problem Todd Huttenstine Excel Programming 10 April 12th 04 06:15 PM
For...Each Loop Problem SuperJas Excel Programming 4 April 2nd 04 05:01 AM
Problem with Loop Mike Excel Programming 7 February 26th 04 09:12 PM


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