'Format and spacing check using VBA Macro

Actually I want to check spacing and format of my Values Using VBA Macro. It is a dynamic string say 1 Count (Pack of 1) or 2 Count (Pack of 1), 20 g (Pack of 1) or 50 g (Pack of 2), 100 ml (Pack of 2) or 200 ml (Pack of 1). so the format remains the same but the integer alone changes in each cell. Also I wrote a code using instr function but it is not able to validate and give me the output. I want integer to be be defined as X and format should be the same.

I have mentioned the code below which I tried. I need some concept which can be helpful. I have attached the screenshot which needs to be validated. Thanks a lot. enter image description here

Sub QualityCheck()
Dim LastColumn As Long
Dim X(1 To 20000) As Integer



ActiveSheet.Select

Range("A1").Select
LastColumn = ActiveSheet.Cells(1, Columns.Count).End(xlToLeft).Offset(0, 1).Columns.Select

ActiveCell.Value = "Quality Error"

Range("A1").Select

Set P = Range("A$1:AD$1")
For Each cell In P
    If cell.Value = "ASIN" Then cell.Offset(1, 0).Select
Next

Do While ActiveCell.Value <> ""
    If ActiveCell.Offset(0, -2).Value = "DE" Then
        If ActiveCell.Offset(0, 12).Value Like " Stück ( er Pack)" Then
            ActiveCell.Offset(0, 26).Value = " Correct"
        
        End If
    End If
    
    ActiveCell.Offset(1, 0).Select
    
Loop
    
End Sub

Also I have tried like declaring a varaible like X = 1 to 1000 and concat "X&" Stuck ("&X&"er Pack")" but still it didne work. It would be helpful if I get the syntax to crack the concept. Thanks in advance.



Solution 1:[1]

From what I understood you need to modify this line:

        If ActiveCell.Offset(0, 12).Value Like "*Stück (*er Pack)" Then

This modification goes like this:

Any char - then followed by "Stück (" then ANY CHARS - followed by "er Pack)"

Should work, let me know if it did!

Hope it helps.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Agustin Martin