By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,956 Members | 1,683 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,956 IT Pros & Developers. It's quick & easy.

VBA Type Mismatch in Excel

P: 18
Ive got a Type Mismatch error i keep getting on the same line of a function. After much testing and trying to figure out what im probably not doing right, i decided i would go alittle crazy and make sure everything was the same data type something along the lines of,
Expand|Select|Wrap|Line Numbers
  1. Dim skuAddress As Range
  2. With Worksheets(current_ss)
  3. dim test as string
  4. test = .Cells(1, 1).Value
  5. If CStr(test) <> CStr("sku") Or CStr("Model") Then
  6. Exit Sub
  7. Else
  8.  
its probably something very simple like it always is, but ive tried several combinations of the If statement including
Expand|Select|Wrap|Line Numbers
  1. If test <> "sku" Or "Model" Then
  2. If .Cells(1, 1).Value <> "sku" Or "Model" Then
  3.  
now, ive checked it out, the value of that cell is the word sku, the variable passes the correct phrase, and "seems" identical to the check but something isnt matching up, suggestions guys?
Jun 11 '08 #1
Share this Question
Share on Google+
4 Replies


kadghar
Expert 100+
P: 1,295
when you use AND or OR in VB, you must write complete statements, i.e.

if test = "one" or "two" then

will give you a mistake since "two" is not a boolean or a complete statement.

if test= "one" or test="two" then

is the right way.

HTH
Jun 11 '08 #2

P: 18
bwahaha, your a genious, well maybe not, but close :-P thanks
Jun 11 '08 #3

P: 18
another quick thought came to mind, i have to have a case statement that repeats alot of code twice, so to consolidate would it be possible to do something similar to the If statement and do
Expand|Select|Wrap|Line Numbers
  1. case "sku" or "model"
  2.          blah blah wicked cool and complicated code
  3.  
or would i have to split those cases up
Jun 11 '08 #4

kadghar
Expert 100+
P: 1,295
another quick thought came to mind, i have to have a case statement that repeats alot of code twice, so to consolidate would it be possible to do something similar to the If statement and do
Expand|Select|Wrap|Line Numbers
  1. case "sku" or "model"
  2.          blah blah wicked cool and complicated code
  3.  
or would i have to split those cases up
no, im afraid you're not able to put that on a case, but, you can always use booleans, or use other alternatives:

Expand|Select|Wrap|Line Numbers
  1. dim Boo1 as boolean
  2.  
  3. '[...]
  4. case "sku": boo1=true
  5. case "model" : boo1=true
  6. '[...]
  7. end select
  8.  
  9. if boo1 then
  10. '[a lot of code]
  11. end if
HTH
Jun 12 '08 #5

Post your reply

Sign in to post your reply or Sign up for a free account.