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

This is supposed to loop through a range (move across the row then back
to the beginning of the next) and return every other row in a pop-up
box. I'm getting an 'Else Without an If" error - additionally, is this
the correct code for it? Thank you so much for your help!


Sub CompanionProjectsValidate()

Dim Str As String
Str = ""

Dim k, i As Integer

If CompanionComplete.Value = True Then

With Range("BK25:DG300")

Range("BK27").Select

Do While k < 20

For k = 0 To 19

If ActiveCell.Offset(0, k + 1) < "" Then
Str = Str & ActiveCell.Offset(0, k + 1) & Chr(10)

End If

Next k

ActiveCell.Offset(1, -19).Select

Loop

Else: GoTo 10
End If


If Str = "" Then
GoTo 10
Else: CompanionComplete.Value = False
CompleteValidation.TextBox1.Value = Str
CompleteValidation.Show
End If


10


End Sub

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

If you put

End With

before

Else: GoTo 10

it will compile. Whether or not it will do what you want it do isn't
clear - I don't have time to go further into the logic of the code. For
one thing, it isn't clear to me the point of the with statement at all
- there isn't any expression beginning with a dot in the body of the
statement. I don't think that the with as it is would qualify the next
range expression (by making it relative to the range in the with
header). If that is the sort of thing you want (which would be
extremely confusing to me at least) I would think you would need
.Range("BK27").Select
(note the dot)
More than likely, this isn't what you want - so you could also try
deleting the with statement rather than adding the "end with"

HTH

-John Coleman

wrote:
This is supposed to loop through a range (move across the row then back
to the beginning of the next) and return every other row in a pop-up
box. I'm getting an 'Else Without an If" error - additionally, is this
the correct code for it? Thank you so much for your help!


Sub CompanionProjectsValidate()

Dim Str As String
Str = ""

Dim k, i As Integer

If CompanionComplete.Value = True Then

With Range("BK25:DG300")

Range("BK27").Select

Do While k < 20

For k = 0 To 19

If ActiveCell.Offset(0, k + 1) < "" Then
Str = Str & ActiveCell.Offset(0, k + 1) & Chr(10)

End If

Next k

ActiveCell.Offset(1, -19).Select

Loop

Else: GoTo 10
End If


If Str = "" Then
GoTo 10
Else: CompanionComplete.Value = False
CompleteValidation.TextBox1.Value = Str
CompleteValidation.Show
End If


10


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
macro looping error pm Excel Discussion (Misc queries) 7 May 19th 09 11:24 PM
Looping help please Christy Excel Programming 4 July 14th 06 06:52 PM
Error after last object in the array when looping For...each Gunnar Johansson[_3_] Excel Programming 3 December 14th 04 12:23 PM
Looping Gusset Gadder Excel Programming 2 December 11th 04 09:16 PM
Strange looping behaviour and Error 400 Ross Andren Excel Programming 2 October 4th 04 11:25 AM


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