Solved

Ignore statement

Posted on 2014-03-05
3
218 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 Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Sparklines have been introduced with Excel 2010 and are a useful tool for creating small in-cell charts, used for example in dashboards. Excel 2010 offers three different types of Sparklines: Line, Column and Win/Loss. What it does not offer is a…
How to quickly and accurately populate Word documents with Excel data, charts and images (including Automated Bookmark generation) David Miller (dlmille) Synopsis In this article you’ll learn how to use ExcelToWord! to copy data,charts, shapes …
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

758 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now