ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Two problems. HELP (https://www.excelbanter.com/excel-programming/333200-two-problems-help.html)

Andrzej

Two problems. HELP
 
Hello All,

First problem:

I have code. It acts correctly, but
1) when I fill cells for method drag and drop
2) when I delete a few cells
In these cases displays mistake.
How to improve this??

Second problem:
How to make to my code compared 4 signs as well as it checked the
correctness of formula?
For example:
nag= "NGDf"
x= "NGDf-100R"
and wpis = "NGDf"
Comparison is OK, but if user write something different (NGDf-10000R, or
NGDf-1R, or only NGDf) ?? ???

I need the checking the correctness of formulas:

1) LLLL-000L

2) 000.00.0000

whe L - letter; 0 - number


Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False ' STOP EVENTS
Dim x, nag, wpis As String
Dim k As Integer

k = 1
x = Target.Value

' blokada wpisu niewłaściwej nazwy cechy do zakładki
While k < 254
If Not Application.Intersect(Columns(k), Target) Is Nothing Then

nag = Right(Cells(1, k), 4)
wpis = Left(x, 4)

'compare 4 signs
If nag < wpis Then
MsgBox " Pomyliłeś zakładki!!! " & Chr(10) & _
Chr(10) & " Spróbuj ponownie (Try again) "
Target.Value = ""
End If
End If

k = k + 2
Wend
Application.EnableEvents = True 'REACTIVATE EVENTS




All times are GMT +1. The time now is 03:46 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com