Maximum number of charecters allowed

Swaroon

Active Member
Joined
Nov 18, 2005
Messages
288
Office Version
  1. 365
Hi,
Is it possible to add a piece of code to the formula below to limit the answer eg


Sheets("data").Range("BN" & x + 1).Select
xCustomerShort = ActiveCell.Value

Returns eg:
ActiveCell.Value = "Stephen"

Required :
ActiveCell.Value Limit to 4 = "Step"

thanks
Steve
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
works great, thanks

Is there any way of making the last piece of code a flexible value - pls see below ?

Sheets("data").Range("A" & x + 1).Select
xAgreement = Left(ActiveCell.Value, 10)

Sheets("data").Range("BN" & x + 1).Select
xCustomerLong = Left(ActiveCell.Value, 60)

Sheets("data").Range("BN" & x + 1).Select
xCustomerShort = Left(ActiveCell.Value, xx) total charecters available = 100 so xx needs to max out at 30 (10+60+30 = 100)
 
Upvote 0
Not sure I understand...

Where did the 100 come from?
Is that the Length of ActiveCell.Value ?

You could try
xCustomerShort = Left(ActiveCell.Value, Len(ActiveCell.Value)-60-10)
 
Upvote 0
The code determines the name a file will be saved with - concatenating various data pieces - I have a max of 100 charecters i can use, if I use 10 + 60 = 70 then I have a max of 30 available, if i use 10 + 50 then I have 80 - make sense ? The length of each value will change, max being 10 and 60 but if less used, would want to use on final concat
 
Upvote 0
The length of each value will change
HOW exactly ?
The code you posted has the 10 and 60 hard coded, so the simple solution is to also hard code the 30.

do you have some variables holding the 10 and 60 values?
X = 10
Y = 60

Then in the final line that uses the remainder from 100
Z = 100 - X - Y

xCustomerShort = Left(ActiveCell.Value, Z)
 
Upvote 0
HOW exactly ?
The code you posted has the 10 and 60 hard coded, so the simple solution is to also hard code the 30.

do you have some variables holding the 10 and 60 values?
X = 10
Y = 60

Then in the final line that uses the remainder from 100
Z = 100 - X - Y

xCustomerShort = Left(ActiveCell.Value, Z)
Don't forget to subtract the total length of any delimiters between X & Y and between Y & xCustomerShort also (2 if there is a space between them, 4 if there is a comma/space between them, etc.).
 
Upvote 0

Forum statistics

Threads
1,214,985
Messages
6,122,606
Members
449,089
Latest member
Motoracer88

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