CODING ERRor

N

N.F

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Error in Code 9
Minimizing number of commands 0
Range headings 0
P 1
Need Help with a VBA subroutine 0
Using Collection to also capture range adjacent 10
Interpretation 2
VBA for Dependents shortcut menu 0

Top