How to combine IsError with Left if a cell contains more than 255 characters?

most

Board Regular
Joined
Feb 22, 2011
Messages
106
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
  2. Mobile
How to combine IsError with Left if a cell contains more than 255 characters?

This example works fine as long as no cell has more than 255 characters, if it's more than 255, IsError => run-time error.
VBA Code:
   For C = 10 To 13
     If Application.WorksheetFunction.IsError(Cells(2, C)) Then
       Debug.Print ("N/A or ERROR")
      Else
       Debug.Print Left(Cells(2, C).value, 25)
     End If
   Next C

And doing left och len on a cell with error won't compute.
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
What kind of data are you looking at?

Is it a string of numbers or a string of characters?

The reason that you are getting an error on more than 255, is because that is all an excel formula can handle. Excel will take up to 32565 characters into a cell and left(cell(2,c).text,25) will handle that with no problem
 
Upvote 0
The data looks like this, I'm parsing the data in row 2 into a userform.combo.listbox.
So in some way I need to catch if the cell has an error and in the same time find a solution for Excel formula to only process the first x characters.
1581954512445.png
 
Upvote 0
Try changing this
VBA Code:
   For C = 10 To 13
     If Application.WorksheetFunction.IsError(Cells(2, C)) Then
       Debug.Print ("N/A or ERROR")
      Else
       Debug.Print Left(Cells(2, C).value, 25)
     End If
   Next C

to this

VBA Code:
   For C = 10 To 13
     If Application.WorksheetFunction.IsError(Cells(2, C)) Then
       Debug.Print ("N/A or ERROR")
     End If
       Debug.Print Left(Cells(2, C).text, 25)
   Next C
 
Upvote 0
Almost, needed to add ".text" to second row also. THANKS!

VBA Code:
   For C = 1 To 6
     If Application.WorksheetFunction.IsError(Cells(2, C).Text) Then
       Debug.Print ("N/A or ERROR")
     End If
       Debug.Print Left(Cells(2, C).Text, 25)
   Next C
 
Upvote 0
Or actually I only need to use...
VBA Code:
For C = 1 To 6
Debug.Print Left(Cells(2, C).Text, 25)
Next C
Since "Application.WorksheetFunction.IsError(Cells(2, C).Text)" is never TRUE
 
Upvote 0

Forum statistics

Threads
1,215,036
Messages
6,122,794
Members
449,095
Latest member
m_smith_solihull

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