Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,510
Default Help with what is wrong with code

If you see this question posted twice then my apologies. Something went wrong
before and I can't see it on the forum.
I will appreciate help with the following to tell me what I am doing wrong.

I have these lines of code which work fine:-
Dim c
Dim inputRnge As Range

Set inputRnge = Sheets("Input Data").Range("A:A")
For Each c In inputRnge
If c.Value = 0 Then Exit For
'further code here

However I want to be able to set inputRnge based on the numeric value of the
column which I believe should be like this:

Set inputRnge = Sheets("Input Data").Columns(1)
inputRnge.Select 'This line for testing inputRnge and it works

For Each c In inputRnge
If c.Value = 0 Then Exit For
'further code here

The second lot of code fails on the line If c.Value = 0 Then Exit For with
the error message:
Runtime error 13 Type mismatch.

Note that the only difference between the two lots of code is the set
inputRnge and I have tested the inputRnge with the select which appears to
work so what is wrong with it?

All help greatly appreciated.

Regards,

OssieMac
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,510
Default Help with what is wrong with code

Hi Joel,
Joel,

Thanks for trying to help but unfortunately I get the same error message as
with the code I had.

Just in case anyone else can help, I am using Excel 2002 in case that makes
a difference and the data in the column is all numeric without headers as per
the following sample:-
24
18
24
9
18

Regards,

OssieMac

"Joel" wrote:

try

Set inputRnge = Sheets("Input Data").cells(1,1).entirecolumn


"OssieMac" wrote:

If you see this question posted twice then my apologies. Something went wrong
before and I can't see it on the forum.
I will appreciate help with the following to tell me what I am doing wrong.

I have these lines of code which work fine:-
Dim c
Dim inputRnge As Range

Set inputRnge = Sheets("Input Data").Range("A:A")
For Each c In inputRnge
If c.Value = 0 Then Exit For
'further code here

However I want to be able to set inputRnge based on the numeric value of the
column which I believe should be like this:

Set inputRnge = Sheets("Input Data").Columns(1)
inputRnge.Select 'This line for testing inputRnge and it works

For Each c In inputRnge
If c.Value = 0 Then Exit For
'further code here

The second lot of code fails on the line If c.Value = 0 Then Exit For with
the error message:
Runtime error 13 Type mismatch.

Note that the only difference between the two lots of code is the set
inputRnge and I have tested the inputRnge with the select which appears to
work so what is wrong with it?

All help greatly appreciated.

Regards,

OssieMac

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
What is wrong with this code? jlclyde Excel Discussion (Misc queries) 5 January 9th 08 05:12 PM
Is there something wrong with my code? Corey Excel Programming 5 February 19th 07 02:29 PM
could someone look at my code please and tell me what's wrong? tha Blondie Excel Programming 1 January 12th 07 11:57 PM
What's wrong with this code? PhilipsBernard Excel Programming 4 October 20th 05 07:30 AM
What's wrong with the code,pls hv a look changeable[_10_] Excel Programming 0 November 3rd 04 09:56 AM


All times are GMT +1. The time now is 03:36 AM.

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

About Us

"It's about Microsoft Excel"