VBA Left 6 being very naughty.

RockandGrohl

Well-known Member
Joined
Aug 1, 2018
Messages
596
Office Version
  1. 2010
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

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
36,730
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2010
Platform
  1. Windows
  2. MacOS
Why not make tno a String?
 
Last edited:

RockandGrohl

Well-known Member
Joined
Aug 1, 2018
Messages
596
Office Version
  1. 2010
Platform
  1. Windows
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:

MARK858

MrExcel MVP
Joined
Nov 12, 2010
Messages
14,062
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
  2. Mobile
Just to state that the error
is because Clng is a number and Cstr is a text string
 

Watch MrExcel Video

Forum statistics

Threads
1,130,112
Messages
5,640,174
Members
417,130
Latest member
Darion2021

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
Top