Thread: CODING ERRor
View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.misc
Toppers Toppers is offline
external usenet poster
 
Posts: 4,339
Default CODING ERRor

Is "header" defined ..a named range presumably?

"N.F" wrote:

Hello, I keep getting a yellow arrow highliting the following command:

HeaderRow = Range("Header").Row ' get location of header row.

I get the following error: " Runtime Error 1004
Method 'Range' of object'
_Global failed

Heres part of my code:

Option Explicit

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

Dim i As Long ' output row index
Dim Roww As Long 'input row index

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("Sheet4").Cells(Roww, 2) < "" Then
Coll = Coll + 1 ' bump column index
Sheets("Output").Cells(i, Coll) = " " & Heading1 & "=" &
Sheets("Sheet4").Cells(Roww, 2) & "." ' First field
End If
If Sheets("Sheet4").Cells(Roww, 3) < "" Then
Coll = Coll + 1 ' bump column index
Sheets("Output").Cells(i, Coll) = " " & Heading2 & "=" &
Sheets("Sheet4").Cells(Roww, 3) & "." ' First field
End If
If Sheets("Sheet4").Cells(Roww, 4) < "" Then
Coll = Coll + 1 ' bump column index
Sheets("Output").Cells(i, Coll) = " " & Heading3 & "=" &
Sheets("Sheet4").Cells(Roww, 4) & "." ' First field
End If

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 Sub