Problems with For Each

  • Thread starter Thread starter DKY
  • Start date Start date
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
 
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


Back
Top