# Thread: Solved: variable not defined in

1. ## Solved: variable not defined in

I'm getting the error at x. How do I define this to go through each cell in the range?
[VBA]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[/VBA]

2. Originally Posted by grichey
I'm getting the error at x. How do I define this to go through each cell in the range?
[vba]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[/vba]
[vba]Dim x As Long[/vba]

3. 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.
[VBA]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[/VBA]

You must not have tried this. Long will not work:

5. yeah i dim 'd as object and it worked fine.
Thanks!

6. They are ranges, so why not Dim as ranges. I would go with
[vba]
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

[/vba]

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•