2
I need some help.
I have a spreadsheet this way:
And I want to limit the amount of characters and the type
In the segment column I want to limit it to 6 characters if it is less than 6 or more than 6. Returns msg "Character limit not reached"
In the date column I want to limit the date type to 8 characters if it is less than 8 or more than 8. Returns to msg "Character limit not reached"
And in the number column I want to limit the number type to 4 characters if it is less than 4 or more than 4. Returns to msg "Character limit not reached"
I started writing something, but I’m not seeing where I’m going wrong. And honestly I haven’t written VBA code for a long time
I can’t remember how to select the column and put the macro.
'If there are no 4 numbers If Intsize <> 4 Then Msgbox "Character Limit Not Reached", vbCritical Application.Enableevents = False Rng.Clearcontents Application.Enableevents = True If anyone can help, I’d appreciate it
Código está assim:
Sub LimitarCaractere()
Dim TRACKER As Workbook '<-- Tracker
Dim MARKET As Worksheet '<-- Aba
Dim i As Long '<-- Linha selecionada
Dim SEGM As String '<-- Segment
Dim FLT As Integer '<-- Flight
Dim Ddate As Date '<-- Date
Set TRACKER = ActiveWorkbook
Set MARKET = TRACKER.ActiveSheet
i = ActiveCell.Row
'Limita o número de cacteres na célula
If i > 6 Then
ActiveCell = Left(ActiveCell, 6)
MsgBox "Limite de caracteres Ultrapassado na Célula: " _
& ActiveCell
End If
End Sub
Thank you
I apologize for the basics I know, but how can I test the code? I try to run, but open the window to create a name in the macro and I can’t
– Thais
@To test, change the values of the spreadsheet you entered the code. The data are in column B, C and F?
– danieltakeshi
I already made the changes yes. But I can’t execute the code. I run in run, open a macros name window and do not find Worksheet_change, and if I shoot from Private tbm does not work
– Thais
@Thais As I said, it is not to run this way. This code uses events to run. Therefore every time the desired worksheet undergoes some change, this macro is triggered. Try to insert some value into a Worksheet cell where the code was inserted.
– danieltakeshi
thank you so much for the excellent explanation, I managed to understand clearly, I will test here and I already mark the answer. Thank you!!!
– Thais
I entered several values in columns B, C and F, saved and opened again. And did not change anything
– Thais
The code does not change, it only checks if these values are correct at the time of entering, if it is incorrect, a message appears.
– danieltakeshi
I got it, I even did a good research on what this event is. I did several tests and it does not appear to msg. I must be missing something.
– Thais
I got it right here. It worked!! Thank you so much!!
– Thais