PDA

View Full Version : Solved: variable not defined in



grichey
06-12-2008, 07:34 AM
I'm getting the error at x. How do I define this to go through each cell in the range?
Option Explicit
Sub dumpts()
Dim myRange As Object


'Dim yrend As Integer
'yrend = 7

'Do

' Sheets("P200" & yrend).Select

Set myRange = Application.InputBox("Range?", "Range?", Type:=8)

For Each x In myRange
If (x.Value) = "T" Then
x.Select
Selection = "0"

End If
'yrend = yrend + 1

'Loop Until yrend = 9

Next x

End Sub

LinkND
06-12-2008, 07:41 AM
I'm getting the error at x. How do I define this to go through each cell in the range?
Option Explicit
Sub dumpts()
Dim myRange As Object


'Dim yrend As Integer
'yrend = 7

'Do

' Sheets("P200" & yrend).Select

Set myRange = Application.InputBox("Range?", "Range?", Type:=8)

For Each x In myRange
If (x.Value) = "T" Then
x.Select
Selection = "0"

End If
'yrend = yrend + 1

'Loop Until yrend = 9

Next x

End Sub

Dim x As Long

lucas
06-12-2008, 07:43 AM
You must dim it as variant or as an object.......I think variant in this case. If you just use dim x it will be dimmed as variant.
Option Explicit
Sub dumpts()
Dim myRange As Object
Dim x


'Dim yrend As Integer
'yrend = 7

'Do

' Sheets("P200" & yrend).Select

Set myRange = Application.InputBox("Range?", "Range?", Type:=8)

For Each x In myRange
If (x.Value) = "T" Then
x.Select
Selection = "0"

End If
'yrend = yrend + 1

'Loop Until yrend = 9

Next x

End Sub

lucas
06-12-2008, 07:48 AM
LinkND,
You must not have tried this. Long will not work:

grichey
06-12-2008, 08:48 AM
yeah i dim 'd as object and it worked fine.
Thanks!

mdmackillop
06-12-2008, 09:06 AM
They are ranges, so why not Dim as ranges. I would go with

Option Explicit
Sub dumpts()
Dim myRange As Range
Dim x As Range
Set myRange = Application.InputBox("Range?", "Range?", Type:=8)
For Each x In myRange
If x = "T" Then x = "0"
Next x
End Sub