ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Error in Code (https://www.excelbanter.com/excel-discussion-misc-queries/148172-error-code.html)

N.F[_2_]

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

FSt1

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


N.F[_2_]

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


FSt1

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


FSt1

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


N.F[_2_]

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


Jennifer[_2_]

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




N.F[_2_]

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


FSt1

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


N.F[_2_]

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






All times are GMT +1. The time now is 03:46 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com