Thread: Error in Code
View Single Post
  #10   Report Post  
Posted to microsoft.public.excel.misc
N.F[_2_] N.F[_2_] is offline
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