Problems with For Each

D

DKY

I have the code below but it gives me an error and tells me to defin
the variable 'cell' in the For Each cell In Selection part. Why is i
doing that?


Code
-------------------
LRow = Cells(Rows.Count, "E").End(xlUp).Row
Range("A2:A" & LRow).Select
' START CHANGE NUMBER TO TEXT
For Each cell In Selection
cell.NumberFormat = "@"
cell.Value = Trim(cell.Value)

' If cell.Value <> "" Then
' TempString = Trim(UCase(cell.Value))
' cell.Value = TempString
' End If
Next cel
 
J

Jake Marx

Hi DKY,

If you're using Option Explicit, you'll have to declare "cell" as an Object
or Range variable. So put the following line of code above your loop and
you should be fine:

Dim cell As Range

--
Regards,

Jake Marx
MS MVP - Excel
www.longhead.com

[please keep replies in the newsgroup - email address unmonitored]
 

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

help please 4
Add Trim Function to Code 4
Compile Error 5
For Each minor problem 7
hyperlink creation problem 1
run time error 91 1
Delete part of cell value 2
runtime 1004 error 3

Top