Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Ignore statement

Posted on 2014-03-05
3
226 Views
Last Modified: 2014-03-10
I am using the following piece of code which works fine when there is data to collect

strRange = Left(strRange, Len(strRange) - 1)
.Range(strRange).Copy

But it falls over with the statement 'Invalid procedure call or argument' when there is no data.

Could an expert out there provide me with the code that will move the code past this so that it does not fall over when there is no data

Thanks
0
Comment
Question by:Jagwarman
  • 2
3 Comments
 
LVL 19

Accepted Solution

by:
regmigrant earned 400 total points
ID: 39906744
before the line that fails you can put 'on error resume next' if you know this is the only reason for the error.

its usually better to code around this sort of thing though by checking to see if the range is available. for example the following makes sure that strrange is at least 2 characters before trying to shorten it (your code should be trying to prove its a valid range as well)

If strRange > 2 then    
 strRange = Left(strRange, Len(strRange) - 1)
   .range(...
Endif
0
 
LVL 39

Assisted Solution

by:nutsch
nutsch earned 100 total points
ID: 39906817
I agree with regmigrant on the approach, but he most likely intended his code to be the following (with the len() function):

If len(strRange) > 2 then    
 strRange = Left(strRange, Len(strRange) - 1)
   .range(...
Endif 

Open in new window


Thomas
0
 
LVL 19

Expert Comment

by:regmigrant
ID: 39907999
d'oh, thanks for the catch
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

792 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question