VBA Left 6 being very naughty.

RockandGrohl

Well-known Member
Joined
Aug 1, 2018
Messages
810
Office Version
  1. 365
Platform
  1. Windows
Christ, me again, same topic.

Have a look at this:

Code:
If Cells(ActiveCell.Row, "C").Value = tnam And [B]Left(Cells(ActiveCell.Row, "A").Value, 6)[/B] <> tno And InStr(1, Cells(ActiveCell.Row, "K").Value, pup) > 0 Then

The left bit is giving me no end of grief.

So the fabled "tno" variable is "702228"

It goes down this huge list, finds the tnam, looks across at A and sees 702228, this is invalid so it goes down another row.

Now it sees tnam, same as before, looks across and sees 702228-F, but it's only supposed to look at the 6 characters to the left, which is 702228.


It found 702228 invalid before, but not when it's 702228-F cut down to 702228.


Could it be because 702228 is an integer and 702228-F cut down to 702228 is a string?

How would I rectify this?

And CLng(Left(Cells(ActiveCell.Row, "A").Value, 6))

That should do the trick, right (CInt gave overflow error)
 
Last edited:

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Why not make tno a String?
 
Last edited:
Upvote 0
Why not make tno a String?

I just set tno as a string by doing CLng(variable) and it says "Type mismatch" :(

However I set it as Cstr and it worked, hooray :D Thanks.
 
Last edited:
Upvote 0
Just to state that the error
is because Clng is a number and Cstr is a text string
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,176
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top