View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 27,285
Default <Method 'Range' of object '_Global' failed error

Invalid syntax

Range(Cells(1, typeCol)).Value = "Lead Type"

should be

Cells(1, typeCol).Value = "Lead Type"


Range(rng reference, rng reference) works, but Range(rng reference)
doesn't (and is redundant).

--
Regards,
Tom Ogilvy

"Ken Loomis" wrote in message
...
When I run this macro,

Sub addLeadType(leadType As Integer)
Dim totalrows As Integer
Dim typeCol As Integer

typeCol = 11

' The following line generates the error
Range(Cells(1, typeCol)).Value = "Lead Type"


totalrows = ActiveSheet.UsedRange.Rows.count
Range(Cells(2, typeCol), Cells(totalrows, typeCol)).Value = leadType
End Sub

I get a "<Method 'Range' of object '_Global' failed error at the line
indicated above.

I tried hard coding the "11" in place of typeCol and get the same error.

Can someone tell me what I am doing wrong here?

Thanks,
Ken Loomis