Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Problems with For Each


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
-------------------

--
DK
-----------------------------------------------------------------------
DKY's Profile: http://www.excelforum.com/member.php...fo&userid=1451
View this thread: http://www.excelforum.com/showthread.php?threadid=39345

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 860
Default Problems with For Each

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]


DKY wrote:
I have the code below but it gives me an error and tells me to define
the variable 'cell' in the For Each cell In Selection part. Why is it
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 cell
--------------------


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Problems with For Each


Oh, I just removed Option Explicit. What's Option Explicit for anyway

--
DK
-----------------------------------------------------------------------
DKY's Profile: http://www.excelforum.com/member.php...fo&userid=1451
View this thread: http://www.excelforum.com/showthread.php?threadid=39345

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Problems with For Each

Hi DKY,

The Option Explicit statement requires that all variables be declared and
that the be declared explicitly.

See Chip Pearson's 'Using Variables (Properly) In VBA' page at:

http://www.cpearson.com/excel/variables.htm

for a detailed discussion of the issue.

Perhaps, prior to reading the above, you might profitably visit Chip's
'Declaring Variables In VBA' page at:

http://www.cpearson.com/excel/DeclaringVariables.htm


---
Regards,
Norman



"DKY" wrote in message
...

Oh, I just removed Option Explicit. What's Option Explicit for anyway?


--
DKY
------------------------------------------------------------------------
DKY's Profile:
http://www.excelforum.com/member.php...o&userid=14515
View this thread: http://www.excelforum.com/showthread...hreadid=393455



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Problems with For Each


DKY

I asked the same question. Here is the answer.

http://www.excelforum.com/showthread.php?t=384692

this Help?
Dave
DKY Wrote:
Oh, I just removed Option Explicit. What's Option Explicit for anyway?



--
Piranha
------------------------------------------------------------------------
Piranha's Profile: http://www.excelforum.com/member.php...o&userid=20435
View this thread: http://www.excelforum.com/showthread...hreadid=393455



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problems with ngs T. Valko Excel Worksheet Functions 2 January 6th 10 12:05 AM
aauugghhh...#div/o problems & various average formula problems acbel40 Excel Worksheet Functions 5 October 19th 09 05:00 PM
Tab Key problems ESL in Tyler Excel Discussion (Misc queries) 2 March 21st 05 11:01 PM
RTD Problems Jonathan Pinnock Excel Programming 0 October 8th 04 09:43 AM
Problems merging an excel file due to code or file problems? Cindy M -WordMVP- Excel Programming 0 September 14th 04 02:58 PM


All times are GMT +1. The time now is 11:25 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"