Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Get cell value

Hello

I'm trying to get the cell value, if the cell has a value over a certain
range, but when I run this, I keep getting a run time error. Any ideas?
Can I not use the range funtion like this?

Sub CellValue()
Dim x
For Each x In Range("c1:c100")
If Not IsEmpty(x) Then
Debug.Print "The value is " & Range(x).Text
End If
Next x
End Sub


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Get cell value

It is usually helpful to tell us exactly what error message you are getting
and which line it is occurring on. With that said, I think your problem is
in the Debug.Print statement, namely, the variable "x" is already a range,
so you don't have to encase it in a call to Range. Try that line like
this...

Debug.Print "The value is " & x.Text

--
Rick (MVP - Excel)



"Jason" wrote in message
...
Hello

I'm trying to get the cell value, if the cell has a value over a certain
range, but when I run this, I keep getting a run time error. Any ideas?
Can I not use the range funtion like this?

Sub CellValue()
Dim x
For Each x In Range("c1:c100")
If Not IsEmpty(x) Then
Debug.Print "The value is " & Range(x).Text
End If
Next x
End Sub

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Get cell value

The error I was getting was Run-time error '1004':
Application-defined or object-defined error


Made the change, you recommned, and that resolved my issue, thanks


"Rick Rothstein" wrote in message
...
It is usually helpful to tell us exactly what error message you are
getting and which line it is occurring on. With that said, I think your
problem is in the Debug.Print statement, namely, the variable "x" is
already a range, so you don't have to encase it in a call to Range. Try
that line like this...

Debug.Print "The value is " & x.Text

--
Rick (MVP - Excel)



"Jason" wrote in message
...
Hello

I'm trying to get the cell value, if the cell has a value over a certain
range, but when I run this, I keep getting a run time error. Any ideas?
Can I not use the range funtion like this?

Sub CellValue()
Dim x
For Each x In Range("c1:c100")
If Not IsEmpty(x) Then
Debug.Print "The value is " & Range(x).Text
End If
Next x
End Sub



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Get cell value

So as I find a cell that isn't empty, how do I actually get a hold of that
cell location, i.e c2 c5 c10 ?


For Each x In Range("c1:c100")
If Not IsEmpty(x) Then
Debug.Print "The value is " & x.Text
MsgBox ActiveCell.Address

End If
Next x
"Rick Rothstein" wrote in message
...
It is usually helpful to tell us exactly what error message you are
getting and which line it is occurring on. With that said, I think your
problem is in the Debug.Print statement, namely, the variable "x" is
already a range, so you don't have to encase it in a call to Range. Try
that line like this...

Debug.Print "The value is " & x.Text

--
Rick (MVP - Excel)



"Jason" wrote in message
...
Hello

I'm trying to get the cell value, if the cell has a value over a certain
range, but when I run this, I keep getting a run time error. Any ideas?
Can I not use the range funtion like this?

Sub CellValue()
Dim x
For Each x In Range("c1:c100")
If Not IsEmpty(x) Then
Debug.Print "The value is " & Range(x).Text
End If
Next x
End Sub



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Get cell value

Dim x as range

For Each x In Range("c1:c100").cells
If Not IsEmpty(x) Then
Debug.Print "The value is " & x.Text
MsgBox x.Address
exit for 'if you want to stop after the first non-empty cell.
End If
Next x



Jason wrote:

So as I find a cell that isn't empty, how do I actually get a hold of that
cell location, i.e c2 c5 c10 ?

For Each x In Range("c1:c100")
If Not IsEmpty(x) Then
Debug.Print "The value is " & x.Text
MsgBox ActiveCell.Address

End If
Next x
"Rick Rothstein" wrote in message
...
It is usually helpful to tell us exactly what error message you are
getting and which line it is occurring on. With that said, I think your
problem is in the Debug.Print statement, namely, the variable "x" is
already a range, so you don't have to encase it in a call to Range. Try
that line like this...

Debug.Print "The value is " & x.Text

--
Rick (MVP - Excel)



"Jason" wrote in message
...
Hello

I'm trying to get the cell value, if the cell has a value over a certain
range, but when I run this, I keep getting a run time error. Any ideas?
Can I not use the range funtion like this?

Sub CellValue()
Dim x
For Each x In Range("c1:c100")
If Not IsEmpty(x) Then
Debug.Print "The value is " & Range(x).Text
End If
Next x
End Sub


--

Dave Peterson


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Get cell value

Why are you MessagBox'ing the ActiveCell's address? Inside the For Each
loop, the loop variable (your 'x' variable in this case) references the cell
being looked at during each iteration of the loop... just use it... it is a
Range variable. I'm assuming you have Dim'med 'x' as a Range variable
although if you didn't, it will be a (slower) Variant and that should still
work.

Dim x As Range
......
......
For Each x In Range("C1:C100")
If Not IsEmpty(x) Then
MsgBox x.Address
End If
Next

--
Rick (MVP - Excel)



"Jason" wrote in message
...
So as I find a cell that isn't empty, how do I actually get a hold of that
cell location, i.e c2 c5 c10 ?


For Each x In Range("c1:c100")
If Not IsEmpty(x) Then
Debug.Print "The value is " & x.Text
MsgBox ActiveCell.Address

End If
Next x
"Rick Rothstein" wrote in message
...
It is usually helpful to tell us exactly what error message you are
getting and which line it is occurring on. With that said, I think your
problem is in the Debug.Print statement, namely, the variable "x" is
already a range, so you don't have to encase it in a call to Range. Try
that line like this...

Debug.Print "The value is " & x.Text

--
Rick (MVP - Excel)



"Jason" wrote in message
...
Hello

I'm trying to get the cell value, if the cell has a value over a certain
range, but when I run this, I keep getting a run time error. Any ideas?
Can I not use the range funtion like this?

Sub CellValue()
Dim x
For Each x In Range("c1:c100")
If Not IsEmpty(x) Then
Debug.Print "The value is " & Range(x).Text
End If
Next x
End Sub



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
Code to copy the formulae of one cell to all the cell in the rangewith the specific cell and columnnumber changing Options Yuvraj Excel Discussion (Misc queries) 0 June 29th 09 11:20 AM
Populate a cell if values in cell 1 and cell 2 match cell 3 and 4 [email protected] Excel Worksheet Functions 1 August 22nd 08 02:04 AM
Populate a cell if values in cell 1 and cell 2 match cell 3 and 4 [email protected] Excel Programming 1 August 21st 08 10:13 PM
NEED VBA TO SELECT A CELL; NOTE THE CELL VALUE;COPYADJ CELL;FIND CELL VALUE IN A RANGE AND SO ON CAPTGNVR Excel Programming 2 July 8th 07 04:18 PM
How to create/run "cell A equals Cell B put Cell C info in Cell D abmb161 Excel Discussion (Misc queries) 5 January 26th 06 06:36 PM


All times are GMT +1. The time now is 07:05 PM.

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"