#1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 65
Default Error in Code

Hello, I am trying to figure out what is wrong with my code but cannot figure
it out
Anyone?? Thank you so much in advance. im sure the solution is simple im
just not seeing it!
I keep getting a compile error: " Do without Loop"


Heres part of my code;

Sub GenerateTextFile()
Dim Coll As Integer ' output column index
Dim HeaderRow As Long
Dim Heading1 As String
Dim Heading2 As String
Dim Heading3 As String

HeaderRow = Range("Header").Row ' get location of header row.
Heading1 = Sheets("Sheet1").Cells(HeaderRow, 2) ' get headings
Heading2 = Sheets("Sheet1").Cells(HeaderRow, 3)
Heading3 = Sheets("Sheet1").Cells(HeaderRow, 4)

Sheets("Output").Cells.ClearContents ' clear output sheet
Roww = HeaderRow + 1 ' first row
i = 1
Do
Coll = 1
Sheets("Output").Cells(i, Coll) = "&D" ' First field

If Sheets("Sheet1").Cells(Roww, 2) < "" Then
Coll = Coll + 1 ' bump column index
Sheets("Output").Cells(i, Coll) = " " & Heading1 & "=" &
Sheets("Sheet1").Cells(Roww, 2) & "." ' First field
End If
If Sheets("Sheet1").Cells(Roww, 3) < "" Then
Coll = Coll + 1 ' bump column index
Sheets("Output").Cells(i, Coll) = " " & Heading2 & "=" &
Sheets("Sheet1").Cells(Roww, 3) & "." ' First field
End If
If Sheets("Sheet1").Cells(Roww, 4) < "" Then
Coll = Coll + 1 ' bump column index
Sheets("Output").Cells(i, Coll) = " " & Heading3 & "=" &
Sheets("Sheet1").Cells(Roww, 4) & "." ' First field
End If

Do
Coll = Coll + 1 ' bump column index
Sheets("Output").Cells(i, Coll) = "/" '
last slash


Roww = Roww + 1 ' next row
i = i + 1
Loop While Sheets("Sheet1").Cells(Roww, 1) < ""
End If
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3,942
Default Error in Code

hi
looks like you have 1 too many end if statements at the bottom just before
end sub.
if you don't have an end if for each if when using a do statement, you will
get the do without a loop error message.
yeah, i know. confusing.

regards
FSt1

"N.F" wrote:

Hello, I am trying to figure out what is wrong with my code but cannot figure
it out
Anyone?? Thank you so much in advance. im sure the solution is simple im
just not seeing it!
I keep getting a compile error: " Do without Loop"


Heres part of my code;

Sub GenerateTextFile()
Dim Coll As Integer ' output column index
Dim HeaderRow As Long
Dim Heading1 As String
Dim Heading2 As String
Dim Heading3 As String

HeaderRow = Range("Header").Row ' get location of header row.
Heading1 = Sheets("Sheet1").Cells(HeaderRow, 2) ' get headings
Heading2 = Sheets("Sheet1").Cells(HeaderRow, 3)
Heading3 = Sheets("Sheet1").Cells(HeaderRow, 4)

Sheets("Output").Cells.ClearContents ' clear output sheet
Roww = HeaderRow + 1 ' first row
i = 1
Do
Coll = 1
Sheets("Output").Cells(i, Coll) = "&D" ' First field

If Sheets("Sheet1").Cells(Roww, 2) < "" Then
Coll = Coll + 1 ' bump column index
Sheets("Output").Cells(i, Coll) = " " & Heading1 & "=" &
Sheets("Sheet1").Cells(Roww, 2) & "." ' First field
End If
If Sheets("Sheet1").Cells(Roww, 3) < "" Then
Coll = Coll + 1 ' bump column index
Sheets("Output").Cells(i, Coll) = " " & Heading2 & "=" &
Sheets("Sheet1").Cells(Roww, 3) & "." ' First field
End If
If Sheets("Sheet1").Cells(Roww, 4) < "" Then
Coll = Coll + 1 ' bump column index
Sheets("Output").Cells(i, Coll) = " " & Heading3 & "=" &
Sheets("Sheet1").Cells(Roww, 4) & "." ' First field
End If

Do
Coll = Coll + 1 ' bump column index
Sheets("Output").Cells(i, Coll) = "/" '
last slash


Roww = Roww + 1 ' next row
i = i + 1
Loop While Sheets("Sheet1").Cells(Roww, 1) < ""
End If
End Sub

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 65
Default Error in Code

Thanks for your help, but now that I deleted that End if statement
Now I get an error saying "Block If without End If " error

"FSt1" wrote:

hi
looks like you have 1 too many end if statements at the bottom just before
end sub.
if you don't have an end if for each if when using a do statement, you will
get the do without a loop error message.
yeah, i know. confusing.

regards
FSt1

"N.F" wrote:

Hello, I am trying to figure out what is wrong with my code but cannot figure
it out
Anyone?? Thank you so much in advance. im sure the solution is simple im
just not seeing it!
I keep getting a compile error: " Do without Loop"


Heres part of my code;

Sub GenerateTextFile()
Dim Coll As Integer ' output column index
Dim HeaderRow As Long
Dim Heading1 As String
Dim Heading2 As String
Dim Heading3 As String

HeaderRow = Range("Header").Row ' get location of header row.
Heading1 = Sheets("Sheet1").Cells(HeaderRow, 2) ' get headings
Heading2 = Sheets("Sheet1").Cells(HeaderRow, 3)
Heading3 = Sheets("Sheet1").Cells(HeaderRow, 4)

Sheets("Output").Cells.ClearContents ' clear output sheet
Roww = HeaderRow + 1 ' first row
i = 1
Do
Coll = 1
Sheets("Output").Cells(i, Coll) = "&D" ' First field

If Sheets("Sheet1").Cells(Roww, 2) < "" Then
Coll = Coll + 1 ' bump column index
Sheets("Output").Cells(i, Coll) = " " & Heading1 & "=" &
Sheets("Sheet1").Cells(Roww, 2) & "." ' First field
End If
If Sheets("Sheet1").Cells(Roww, 3) < "" Then
Coll = Coll + 1 ' bump column index
Sheets("Output").Cells(i, Coll) = " " & Heading2 & "=" &
Sheets("Sheet1").Cells(Roww, 3) & "." ' First field
End If
If Sheets("Sheet1").Cells(Roww, 4) < "" Then
Coll = Coll + 1 ' bump column index
Sheets("Output").Cells(i, Coll) = " " & Heading3 & "=" &
Sheets("Sheet1").Cells(Roww, 4) & "." ' First field
End If

Do
Coll = Coll + 1 ' bump column index
Sheets("Output").Cells(i, Coll) = "/" '
last slash


Roww = Roww + 1 ' next row
i = i + 1
Loop While Sheets("Sheet1").Cells(Roww, 1) < ""
End If
End Sub

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3,942
Default Error in Code

hi,
based on the code you posted, I count 3 ifs and 4 end ifs.
3 ifs and end ifs before the do loop and 1 end if inside the do loop(without
an if).
count all your ifs and end ifs and make sure you have 1 for 1.
post back with results.
regards
FSt1
"N.F" wrote:

Thanks for your help, but now that I deleted that End if statement
Now I get an error saying "Block If without End If " error

"FSt1" wrote:

hi
looks like you have 1 too many end if statements at the bottom just before
end sub.
if you don't have an end if for each if when using a do statement, you will
get the do without a loop error message.
yeah, i know. confusing.

regards
FSt1

"N.F" wrote:

Hello, I am trying to figure out what is wrong with my code but cannot figure
it out
Anyone?? Thank you so much in advance. im sure the solution is simple im
just not seeing it!
I keep getting a compile error: " Do without Loop"


Heres part of my code;

Sub GenerateTextFile()
Dim Coll As Integer ' output column index
Dim HeaderRow As Long
Dim Heading1 As String
Dim Heading2 As String
Dim Heading3 As String

HeaderRow = Range("Header").Row ' get location of header row.
Heading1 = Sheets("Sheet1").Cells(HeaderRow, 2) ' get headings
Heading2 = Sheets("Sheet1").Cells(HeaderRow, 3)
Heading3 = Sheets("Sheet1").Cells(HeaderRow, 4)

Sheets("Output").Cells.ClearContents ' clear output sheet
Roww = HeaderRow + 1 ' first row
i = 1
Do
Coll = 1
Sheets("Output").Cells(i, Coll) = "&D" ' First field

If Sheets("Sheet1").Cells(Roww, 2) < "" Then
Coll = Coll + 1 ' bump column index
Sheets("Output").Cells(i, Coll) = " " & Heading1 & "=" &
Sheets("Sheet1").Cells(Roww, 2) & "." ' First field
End If
If Sheets("Sheet1").Cells(Roww, 3) < "" Then
Coll = Coll + 1 ' bump column index
Sheets("Output").Cells(i, Coll) = " " & Heading2 & "=" &
Sheets("Sheet1").Cells(Roww, 3) & "." ' First field
End If
If Sheets("Sheet1").Cells(Roww, 4) < "" Then
Coll = Coll + 1 ' bump column index
Sheets("Output").Cells(i, Coll) = " " & Heading3 & "=" &
Sheets("Sheet1").Cells(Roww, 4) & "." ' First field
End If

Do
Coll = Coll + 1 ' bump column index
Sheets("Output").Cells(i, Coll) = "/" '
last slash


Roww = Roww + 1 ' next row
i = i + 1
Loop While Sheets("Sheet1").Cells(Roww, 1) < ""
End If
End Sub

  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3,942
Default Error in Code

hi,
excuse me. I did spot an extra do. up near the top after i=1. but i'm still
counting an odd numer of ifs and end ifs.

Regards
FSt1

"FSt1" wrote:

hi,
based on the code you posted, I count 3 ifs and 4 end ifs.
3 ifs and end ifs before the do loop and 1 end if inside the do loop(without
an if).
count all your ifs and end ifs and make sure you have 1 for 1.
post back with results.
regards
FSt1
"N.F" wrote:

Thanks for your help, but now that I deleted that End if statement
Now I get an error saying "Block If without End If " error

"FSt1" wrote:

hi
looks like you have 1 too many end if statements at the bottom just before
end sub.
if you don't have an end if for each if when using a do statement, you will
get the do without a loop error message.
yeah, i know. confusing.

regards
FSt1

"N.F" wrote:

Hello, I am trying to figure out what is wrong with my code but cannot figure
it out
Anyone?? Thank you so much in advance. im sure the solution is simple im
just not seeing it!
I keep getting a compile error: " Do without Loop"


Heres part of my code;

Sub GenerateTextFile()
Dim Coll As Integer ' output column index
Dim HeaderRow As Long
Dim Heading1 As String
Dim Heading2 As String
Dim Heading3 As String

HeaderRow = Range("Header").Row ' get location of header row.
Heading1 = Sheets("Sheet1").Cells(HeaderRow, 2) ' get headings
Heading2 = Sheets("Sheet1").Cells(HeaderRow, 3)
Heading3 = Sheets("Sheet1").Cells(HeaderRow, 4)

Sheets("Output").Cells.ClearContents ' clear output sheet
Roww = HeaderRow + 1 ' first row
i = 1
Do
Coll = 1
Sheets("Output").Cells(i, Coll) = "&D" ' First field

If Sheets("Sheet1").Cells(Roww, 2) < "" Then
Coll = Coll + 1 ' bump column index
Sheets("Output").Cells(i, Coll) = " " & Heading1 & "=" &
Sheets("Sheet1").Cells(Roww, 2) & "." ' First field
End If
If Sheets("Sheet1").Cells(Roww, 3) < "" Then
Coll = Coll + 1 ' bump column index
Sheets("Output").Cells(i, Coll) = " " & Heading2 & "=" &
Sheets("Sheet1").Cells(Roww, 3) & "." ' First field
End If
If Sheets("Sheet1").Cells(Roww, 4) < "" Then
Coll = Coll + 1 ' bump column index
Sheets("Output").Cells(i, Coll) = " " & Heading3 & "=" &
Sheets("Sheet1").Cells(Roww, 4) & "." ' First field
End If

Do
Coll = Coll + 1 ' bump column index
Sheets("Output").Cells(i, Coll) = "/" '
last slash


Roww = Roww + 1 ' next row
i = i + 1
Loop While Sheets("Sheet1").Cells(Roww, 1) < ""
End If
End Sub



  #6   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 65
Default Error in Code

I counted carefully the If's and End If's statements and I have "Do Without
Loop Messege"

I would send you my entire code but its too long.


"FSt1" wrote:

hi,
based on the code you posted, I count 3 ifs and 4 end ifs.
3 ifs and end ifs before the do loop and 1 end if inside the do loop(without
an if).
count all your ifs and end ifs and make sure you have 1 for 1.
post back with results.
regards
FSt1
"N.F" wrote:

Thanks for your help, but now that I deleted that End if statement
Now I get an error saying "Block If without End If " error

"FSt1" wrote:

hi
looks like you have 1 too many end if statements at the bottom just before
end sub.
if you don't have an end if for each if when using a do statement, you will
get the do without a loop error message.
yeah, i know. confusing.

regards
FSt1

"N.F" wrote:

Hello, I am trying to figure out what is wrong with my code but cannot figure
it out
Anyone?? Thank you so much in advance. im sure the solution is simple im
just not seeing it!
I keep getting a compile error: " Do without Loop"


Heres part of my code;

Sub GenerateTextFile()
Dim Coll As Integer ' output column index
Dim HeaderRow As Long
Dim Heading1 As String
Dim Heading2 As String
Dim Heading3 As String

HeaderRow = Range("Header").Row ' get location of header row.
Heading1 = Sheets("Sheet1").Cells(HeaderRow, 2) ' get headings
Heading2 = Sheets("Sheet1").Cells(HeaderRow, 3)
Heading3 = Sheets("Sheet1").Cells(HeaderRow, 4)

Sheets("Output").Cells.ClearContents ' clear output sheet
Roww = HeaderRow + 1 ' first row
i = 1
Do
Coll = 1
Sheets("Output").Cells(i, Coll) = "&D" ' First field

If Sheets("Sheet1").Cells(Roww, 2) < "" Then
Coll = Coll + 1 ' bump column index
Sheets("Output").Cells(i, Coll) = " " & Heading1 & "=" &
Sheets("Sheet1").Cells(Roww, 2) & "." ' First field
End If
If Sheets("Sheet1").Cells(Roww, 3) < "" Then
Coll = Coll + 1 ' bump column index
Sheets("Output").Cells(i, Coll) = " " & Heading2 & "=" &
Sheets("Sheet1").Cells(Roww, 3) & "." ' First field
End If
If Sheets("Sheet1").Cells(Roww, 4) < "" Then
Coll = Coll + 1 ' bump column index
Sheets("Output").Cells(i, Coll) = " " & Heading3 & "=" &
Sheets("Sheet1").Cells(Roww, 4) & "." ' First field
End If

Do
Coll = Coll + 1 ' bump column index
Sheets("Output").Cells(i, Coll) = "/" '
last slash


Roww = Roww + 1 ' next row
i = i + 1
Loop While Sheets("Sheet1").Cells(Roww, 1) < ""
End If
End Sub

  #7   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 24
Default Error in Code

You've got 2 Do statements and only 1 Loop. You have an End If
towards the bottom without a beginning If. I've marked them all below
with '== so you can figure out which Do you want.

Jennifer


Sub GenerateTextFile()
Dim Coll As Integer ' output column index
Dim HeaderRow As Long
Dim Heading1 As String
Dim Heading2 As String
Dim Heading3 As String

HeaderRow = Range("Header").Row ' get location of header row.
Heading1 = Sheets("Sheet1").Cells(HeaderRow, 2) ' get
headings
Heading2 = Sheets("Sheet1").Cells(HeaderRow, 3)
Heading3 = Sheets("Sheet1").Cells(HeaderRow, 4)


Sheets("Output").Cells.ClearContents ' clear
output sheet
Roww = HeaderRow + 1 ' first row
i = 1
'==Do
Coll = 1
Sheets("Output").Cells(i, Coll) = "&D" ' First field


If Sheets("Sheet1").Cells(Roww, 2) < "" Then
Coll = Coll + 1 ' bump column index
Sheets("Output").Cells(i, Coll) = " " & Heading1 & "=" &
Sheets("Sheet1").Cells(Roww, 2) & "." ' First field
End If

If Sheets("Sheet1").Cells(Roww, 3) < "" Then
Coll = Coll + 1 ' bump column index
Sheets("Output").Cells(i, Coll) = " " & Heading2 & "=" &
Sheets("Sheet1").Cells(Roww, 3) & "." ' First field
End If

If Sheets("Sheet1").Cells(Roww, 4) < "" Then
Coll = Coll + 1 ' bump column index
Sheets("Output").Cells(i, Coll) = " " & Heading3 & "=" &
Sheets("Sheet1").Cells(Roww, 4) & "." ' First field
End If


'== Do
Coll = Coll + 1 ' bump column index
Sheets("Output").Cells(i, Coll) =
"/" '
last slash

Roww = Roww + 1 ' next row
i = i + 1
'== Loop While Sheets("Sheet1").Cells(Roww, 1) < ""
'== End If
End Sub


On Jun 27, 11:46 am, N.F wrote:
Hello, I am trying to figure out what is wrong with my code but cannot figure
it out
Anyone?? Thank you so much in advance. im sure the solution is simple im
just not seeing it!
I keep getting a compile error: " Do without Loop"

Heres part of my code;

Sub GenerateTextFile()
Dim Coll As Integer ' output column index
Dim HeaderRow As Long
Dim Heading1 As String
Dim Heading2 As String
Dim Heading3 As String

HeaderRow = Range("Header").Row ' get location of header row.
Heading1 = Sheets("Sheet1").Cells(HeaderRow, 2) ' get headings
Heading2 = Sheets("Sheet1").Cells(HeaderRow, 3)
Heading3 = Sheets("Sheet1").Cells(HeaderRow, 4)

Sheets("Output").Cells.ClearContents ' clear output sheet
Roww = HeaderRow + 1 ' first row
i = 1
Do
Coll = 1
Sheets("Output").Cells(i, Coll) = "&D" ' First field

If Sheets("Sheet1").Cells(Roww, 2) < "" Then
Coll = Coll + 1 ' bump column index
Sheets("Output").Cells(i, Coll) = " " & Heading1 & "=" &
Sheets("Sheet1").Cells(Roww, 2) & "." ' First field
End If
If Sheets("Sheet1").Cells(Roww, 3) < "" Then
Coll = Coll + 1 ' bump column index
Sheets("Output").Cells(i, Coll) = " " & Heading2 & "=" &
Sheets("Sheet1").Cells(Roww, 3) & "." ' First field
End If
If Sheets("Sheet1").Cells(Roww, 4) < "" Then
Coll = Coll + 1 ' bump column index
Sheets("Output").Cells(i, Coll) = " " & Heading3 & "=" &
Sheets("Sheet1").Cells(Roww, 4) & "." ' First field
End If

Do
Coll = Coll + 1 ' bump column index
Sheets("Output").Cells(i, Coll) = "/" '
last slash

Roww = Roww + 1 ' next row
i = i + 1
Loop While Sheets("Sheet1").Cells(Roww, 1) < ""
End If
End Sub



  #8   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 65
Default Error in Code

YESSSS!!!! OK FSt1 I think we got it, after looking at it again I fixed the
Ifs and End Ifs and yes, we did have an extra Do. THANK YOU

"FSt1" wrote:

hi,
excuse me. I did spot an extra do. up near the top after i=1. but i'm still
counting an odd numer of ifs and end ifs.

Regards
FSt1

"FSt1" wrote:

hi,
based on the code you posted, I count 3 ifs and 4 end ifs.
3 ifs and end ifs before the do loop and 1 end if inside the do loop(without
an if).
count all your ifs and end ifs and make sure you have 1 for 1.
post back with results.
regards
FSt1
"N.F" wrote:

Thanks for your help, but now that I deleted that End if statement
Now I get an error saying "Block If without End If " error

"FSt1" wrote:

hi
looks like you have 1 too many end if statements at the bottom just before
end sub.
if you don't have an end if for each if when using a do statement, you will
get the do without a loop error message.
yeah, i know. confusing.

regards
FSt1

"N.F" wrote:

Hello, I am trying to figure out what is wrong with my code but cannot figure
it out
Anyone?? Thank you so much in advance. im sure the solution is simple im
just not seeing it!
I keep getting a compile error: " Do without Loop"


Heres part of my code;

Sub GenerateTextFile()
Dim Coll As Integer ' output column index
Dim HeaderRow As Long
Dim Heading1 As String
Dim Heading2 As String
Dim Heading3 As String

HeaderRow = Range("Header").Row ' get location of header row.
Heading1 = Sheets("Sheet1").Cells(HeaderRow, 2) ' get headings
Heading2 = Sheets("Sheet1").Cells(HeaderRow, 3)
Heading3 = Sheets("Sheet1").Cells(HeaderRow, 4)

Sheets("Output").Cells.ClearContents ' clear output sheet
Roww = HeaderRow + 1 ' first row
i = 1
Do
Coll = 1
Sheets("Output").Cells(i, Coll) = "&D" ' First field

If Sheets("Sheet1").Cells(Roww, 2) < "" Then
Coll = Coll + 1 ' bump column index
Sheets("Output").Cells(i, Coll) = " " & Heading1 & "=" &
Sheets("Sheet1").Cells(Roww, 2) & "." ' First field
End If
If Sheets("Sheet1").Cells(Roww, 3) < "" Then
Coll = Coll + 1 ' bump column index
Sheets("Output").Cells(i, Coll) = " " & Heading2 & "=" &
Sheets("Sheet1").Cells(Roww, 3) & "." ' First field
End If
If Sheets("Sheet1").Cells(Roww, 4) < "" Then
Coll = Coll + 1 ' bump column index
Sheets("Output").Cells(i, Coll) = " " & Heading3 & "=" &
Sheets("Sheet1").Cells(Roww, 4) & "." ' First field
End If

Do
Coll = Coll + 1 ' bump column index
Sheets("Output").Cells(i, Coll) = "/" '
last slash


Roww = Roww + 1 ' next row
i = i + 1
Loop While Sheets("Sheet1").Cells(Roww, 1) < ""
End If
End Sub

  #9   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3,942
Default Error in Code

hi,
did you read my last post.
i did find an extra do. up nead the top after i-1. I missed it first time
through and though that the end if was the problem. I have gotten the do
without loop message before because of ifs and end ifs.

sorry.
regards
FSt1
"N.F" wrote:

I counted carefully the If's and End If's statements and I have "Do Without
Loop Messege"

I would send you my entire code but its too long.


"FSt1" wrote:

hi,
based on the code you posted, I count 3 ifs and 4 end ifs.
3 ifs and end ifs before the do loop and 1 end if inside the do loop(without
an if).
count all your ifs and end ifs and make sure you have 1 for 1.
post back with results.
regards
FSt1
"N.F" wrote:

Thanks for your help, but now that I deleted that End if statement
Now I get an error saying "Block If without End If " error

"FSt1" wrote:

hi
looks like you have 1 too many end if statements at the bottom just before
end sub.
if you don't have an end if for each if when using a do statement, you will
get the do without a loop error message.
yeah, i know. confusing.

regards
FSt1

"N.F" wrote:

Hello, I am trying to figure out what is wrong with my code but cannot figure
it out
Anyone?? Thank you so much in advance. im sure the solution is simple im
just not seeing it!
I keep getting a compile error: " Do without Loop"


Heres part of my code;

Sub GenerateTextFile()
Dim Coll As Integer ' output column index
Dim HeaderRow As Long
Dim Heading1 As String
Dim Heading2 As String
Dim Heading3 As String

HeaderRow = Range("Header").Row ' get location of header row.
Heading1 = Sheets("Sheet1").Cells(HeaderRow, 2) ' get headings
Heading2 = Sheets("Sheet1").Cells(HeaderRow, 3)
Heading3 = Sheets("Sheet1").Cells(HeaderRow, 4)

Sheets("Output").Cells.ClearContents ' clear output sheet
Roww = HeaderRow + 1 ' first row
i = 1
Do
Coll = 1
Sheets("Output").Cells(i, Coll) = "&D" ' First field

If Sheets("Sheet1").Cells(Roww, 2) < "" Then
Coll = Coll + 1 ' bump column index
Sheets("Output").Cells(i, Coll) = " " & Heading1 & "=" &
Sheets("Sheet1").Cells(Roww, 2) & "." ' First field
End If
If Sheets("Sheet1").Cells(Roww, 3) < "" Then
Coll = Coll + 1 ' bump column index
Sheets("Output").Cells(i, Coll) = " " & Heading2 & "=" &
Sheets("Sheet1").Cells(Roww, 3) & "." ' First field
End If
If Sheets("Sheet1").Cells(Roww, 4) < "" Then
Coll = Coll + 1 ' bump column index
Sheets("Output").Cells(i, Coll) = " " & Heading3 & "=" &
Sheets("Sheet1").Cells(Roww, 4) & "." ' First field
End If

Do
Coll = Coll + 1 ' bump column index
Sheets("Output").Cells(i, Coll) = "/" '
last slash


Roww = Roww + 1 ' next row
i = i + 1
Loop While Sheets("Sheet1").Cells(Roww, 1) < ""
End If
End Sub

  #10   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 65
Default Error in Code

YESSSS!!!! OK FSt1 I think we got it,!!!! after looking at it again I fixed the
Ifs and End Ifs and yes, we did have an extra Do. THANK YOU

Thanks FSt1 and Jennifer

"Jennifer" wrote:

You've got 2 Do statements and only 1 Loop. You have an End If
towards the bottom without a beginning If. I've marked them all below
with '== so you can figure out which Do you want.

Jennifer


Sub GenerateTextFile()
Dim Coll As Integer ' output column index
Dim HeaderRow As Long
Dim Heading1 As String
Dim Heading2 As String
Dim Heading3 As String

HeaderRow = Range("Header").Row ' get location of header row.
Heading1 = Sheets("Sheet1").Cells(HeaderRow, 2) ' get
headings
Heading2 = Sheets("Sheet1").Cells(HeaderRow, 3)
Heading3 = Sheets("Sheet1").Cells(HeaderRow, 4)


Sheets("Output").Cells.ClearContents ' clear
output sheet
Roww = HeaderRow + 1 ' first row
i = 1
'==Do
Coll = 1
Sheets("Output").Cells(i, Coll) = "&D" ' First field


If Sheets("Sheet1").Cells(Roww, 2) < "" Then
Coll = Coll + 1 ' bump column index
Sheets("Output").Cells(i, Coll) = " " & Heading1 & "=" &
Sheets("Sheet1").Cells(Roww, 2) & "." ' First field
End If

If Sheets("Sheet1").Cells(Roww, 3) < "" Then
Coll = Coll + 1 ' bump column index
Sheets("Output").Cells(i, Coll) = " " & Heading2 & "=" &
Sheets("Sheet1").Cells(Roww, 3) & "." ' First field
End If

If Sheets("Sheet1").Cells(Roww, 4) < "" Then
Coll = Coll + 1 ' bump column index
Sheets("Output").Cells(i, Coll) = " " & Heading3 & "=" &
Sheets("Sheet1").Cells(Roww, 4) & "." ' First field
End If


'== Do
Coll = Coll + 1 ' bump column index
Sheets("Output").Cells(i, Coll) =
"/" '
last slash

Roww = Roww + 1 ' next row
i = i + 1
'== Loop While Sheets("Sheet1").Cells(Roww, 1) < ""
'== End If
End Sub


On Jun 27, 11:46 am, N.F wrote:
Hello, I am trying to figure out what is wrong with my code but cannot figure
it out
Anyone?? Thank you so much in advance. im sure the solution is simple im
just not seeing it!
I keep getting a compile error: " Do without Loop"

Heres part of my code;

Sub GenerateTextFile()
Dim Coll As Integer ' output column index
Dim HeaderRow As Long
Dim Heading1 As String
Dim Heading2 As String
Dim Heading3 As String

HeaderRow = Range("Header").Row ' get location of header row.
Heading1 = Sheets("Sheet1").Cells(HeaderRow, 2) ' get headings
Heading2 = Sheets("Sheet1").Cells(HeaderRow, 3)
Heading3 = Sheets("Sheet1").Cells(HeaderRow, 4)

Sheets("Output").Cells.ClearContents ' clear output sheet
Roww = HeaderRow + 1 ' first row
i = 1
Do
Coll = 1
Sheets("Output").Cells(i, Coll) = "&D" ' First field

If Sheets("Sheet1").Cells(Roww, 2) < "" Then
Coll = Coll + 1 ' bump column index
Sheets("Output").Cells(i, Coll) = " " & Heading1 & "=" &
Sheets("Sheet1").Cells(Roww, 2) & "." ' First field
End If
If Sheets("Sheet1").Cells(Roww, 3) < "" Then
Coll = Coll + 1 ' bump column index
Sheets("Output").Cells(i, Coll) = " " & Heading2 & "=" &
Sheets("Sheet1").Cells(Roww, 3) & "." ' First field
End If
If Sheets("Sheet1").Cells(Roww, 4) < "" Then
Coll = Coll + 1 ' bump column index
Sheets("Output").Cells(i, Coll) = " " & Heading3 & "=" &
Sheets("Sheet1").Cells(Roww, 4) & "." ' First field
End If

Do
Coll = Coll + 1 ' bump column index
Sheets("Output").Cells(i, Coll) = "/" '
last slash

Roww = Roww + 1 ' next row
i = i + 1
Loop While Sheets("Sheet1").Cells(Roww, 1) < ""
End If
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
error in this code [email protected] Excel Worksheet Functions 2 December 5th 06 05:21 AM
Code Error Tom Excel Discussion (Misc queries) 0 February 21st 06 03:01 PM
Error handling in this code L. Howard Kittle Excel Discussion (Misc queries) 4 October 8th 05 12:35 PM
Error Code 481 MBlake Excel Discussion (Misc queries) 1 May 11th 05 01:27 PM
Code error ?? Anthony Excel Discussion (Misc queries) 2 February 9th 05 10:31 PM


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