?
Solved

Ignore statement

Posted on 2014-03-05
3
Medium Priority
?
242 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 1600 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 400 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

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

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

In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
This article describes a serious pitfall that can happen when deleting shapes using VBA.
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

749 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