MrArchitAgarwal
New Member
- Joined
- Sep 9, 2023
- Messages
- 5
- Office Version
- 2021
- Platform
- Windows
I am using 2 Worksheet_Change Events and the code was working great 2 days back but from yesterday the code stopped working and excel started crashing. Please Help.
This is the code I am using for the Worksheet
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
Dim xRInt As Integer
Dim xDStr As String
Dim xFStr As String
Dim xSStr As String
On Error Resume Next
xDStr = "G" 'Data Column
xFStr = "Y" 'Created Column
xSStr = "Z" 'Updated Column
If (Not Application.Intersect(Me.Range("G2:G"), Target) Is Nothing) Then
xRInt = Target.Row
If Me.Range(xFStr & xRInt) = "" Then
Me.Range(xFStr & xRInt) = Format(Now(), "mm/dd/yyyy hh:mm:ss")
End If
Me.Range(xSStr & xRInt) = Format(Now(), "mm/dd/yyyy hh:mm:ss")
End If
'_____________________________________________________________________________________________________________________________
Dim rng As Range
Dim cell As Range
Dim sizes() As String
Dim startSize As String
Dim endSize As String
Dim i As Integer
On Error Resume Next
' Define the range where the sizes should be generated
Set rng = Intersect(Target, Me.Range("J2:J"))
If Not rng Is Nothing Then
Application.EnableEvents = False
For Each cell In rng
If InStr(1, UCase(cell.Value), "-") > 0 Then
' Split the input into start and end sizes
sizes = Split(UCase(cell.Value), "-")
startSize = sizes(0)
endSize = sizes(1)
' Clear the original cell
cell.ClearContents
' Calculate and fill the cells downward with sizes
For i = 0 To 100 ' Increase this number to cover a larger range
cell.Offset(i, 0).Value = startSize
If UCase(startSize) = UCase(endSize) Then Exit For
startSize = GetNextSize(UCase(startSize))
Next i
End If
Next cell
Application.EnableEvents = True
End If
End Sub
Function GetNextSize(currentSize As String) As String
Select Case currentSize
Case "S"
GetNextSize = "M"
Case "M"
GetNextSize = "L"
Case "L"
GetNextSize = "XL"
Case "XL"
GetNextSize = "2XL"
Case "2XL"
GetNextSize = "3XL"
Case Else
GetNextSize = currentSize
End Select
End Function
This is the code I am using for the Worksheet
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
Dim xRInt As Integer
Dim xDStr As String
Dim xFStr As String
Dim xSStr As String
On Error Resume Next
xDStr = "G" 'Data Column
xFStr = "Y" 'Created Column
xSStr = "Z" 'Updated Column
If (Not Application.Intersect(Me.Range("G2:G"), Target) Is Nothing) Then
xRInt = Target.Row
If Me.Range(xFStr & xRInt) = "" Then
Me.Range(xFStr & xRInt) = Format(Now(), "mm/dd/yyyy hh:mm:ss")
End If
Me.Range(xSStr & xRInt) = Format(Now(), "mm/dd/yyyy hh:mm:ss")
End If
'_____________________________________________________________________________________________________________________________
Dim rng As Range
Dim cell As Range
Dim sizes() As String
Dim startSize As String
Dim endSize As String
Dim i As Integer
On Error Resume Next
' Define the range where the sizes should be generated
Set rng = Intersect(Target, Me.Range("J2:J"))
If Not rng Is Nothing Then
Application.EnableEvents = False
For Each cell In rng
If InStr(1, UCase(cell.Value), "-") > 0 Then
' Split the input into start and end sizes
sizes = Split(UCase(cell.Value), "-")
startSize = sizes(0)
endSize = sizes(1)
' Clear the original cell
cell.ClearContents
' Calculate and fill the cells downward with sizes
For i = 0 To 100 ' Increase this number to cover a larger range
cell.Offset(i, 0).Value = startSize
If UCase(startSize) = UCase(endSize) Then Exit For
startSize = GetNextSize(UCase(startSize))
Next i
End If
Next cell
Application.EnableEvents = True
End If
End Sub
Function GetNextSize(currentSize As String) As String
Select Case currentSize
Case "S"
GetNextSize = "M"
Case "M"
GetNextSize = "L"
Case "L"
GetNextSize = "XL"
Case "XL"
GetNextSize = "2XL"
Case "2XL"
GetNextSize = "3XL"
Case Else
GetNextSize = currentSize
End Select
End Function
SR.NO. | BARCODE | PARTY NAME | PARTY CODE | ITEM CODE | STYLE | COLOUR | SIZE | QUANTITY | PURCHASE PRICE | PURCHASE VALUE | % DISC FORWARD | DISCOUNT IN RS. | LANDING COST | WHOLESALE | RETAIL | MRP | WHOLESALE NAME | NAME ARONIUM | PRICE ARONIUM | STATUS - ARONIUM | STATUS - BARCODE | Date Created | Date Modified | Month created | Year Created |
1 | 880401 | J. K. TEXTILES | JK | 2781 | CO-ORD SET | PINK | L | 3 | 1795 | 5385 | 0 | 0 | 1795 | 224 | 280 | 4500 | CO-ORD SET 2781K224J | CO-ORD SET 2781K224J - L PINK | 2700 | UPDATED | PRINTED | ||||
2 | 880402 | J. K. TEXTILES | JK | 2781 | CO-ORD SET | PINK | XL | 3 | 1795 | 5385 | 0 | 0 | 1795 | 224 | 280 | 4500 | CO-ORD SET 2781K224J | CO-ORD SET 2781K224J - XL PINK | 2700 | UPDATED | PRINTED | ||||
3 | 880403 | J. K. TEXTILES | JK | 2782 | CROP TOP - DRAPE | PINK | L | 3 | 1795 | 5385 | 0 | 0 | 1795 | 224 | 280 | 4500 | CROP TOP - DRAPE 2782K224J | CROP TOP - DRAPE 2782K224J - L PINK | 2700 | UPDATED | PRINTED | ||||
4 | 880404 | J. K. TEXTILES | JK | 2782 | CROP TOP - DRAPE | PINK | XL | 3 | 1795 | 5385 | 0 | 0 | 1795 | 224 | 280 | 4500 | CROP TOP - DRAPE 2782K224J | CROP TOP - DRAPE 2782K224J - XL PINK | 2700 | UPDATED | PRINTED | ||||
5 | 880405 | J. K. TEXTILES | JK | 2783 | GOWN | PINK | M | 3 | 1695 | 5085 | 0 | 0 | 1695 | 212 | 270 | 4300 | GOWN 2783K212J | GOWN 2783K212J - M PINK | 2600 | UPDATED | PRINTED | ||||