Here are some suggestions to optimize your code:
Avoid Selecting Ranges: Instead of selecting ranges and then working with them, directly reference the ranges and cells. This helps to avoid the overhead associated with selecting cells.
Replace:
Sub LSTART_DblClickSheets(ByVal Cancel As MSForms.ReturnBoolean"CONCAT")
On Error GoTo ERR1
Application.ScreenUpdating = False
Select
Dim selectedValue As VariantRange("A2").Select
with:
Dim concatSheet As Worksheet
Dim ventasSheet As Worksheet
selectedValue = LSTART.List(LSTART.ListIndex, 0)
Set concatSheet = ThisWorkbook.Sheets("CONCAT")
Set ventasSheetCODART = ThisWorkbookconcatSheet.SheetsRange("ventas""A2")
.Value
Dim concatRange
Use With Statements: Utilize the With statement to work with ranges efficiently without repeating the sheet reference.
Replace:
ActiveCell.Offset(0, As2).Select Range
Set concatRangeCODART = concatSheetActiveCell.Columns(1)Value
ActiveCell.FindOffset(What:=selectedValue, LookIn:=xlValues0, LookAt:=xlWhole1)
If Not concatRange.Select Is Nothing Then
' Retrieve dataCODCLR from= CONCATActiveCell.Value
Dim CODART As Variant
ActiveCell.Offset(0, 1).Select Dim CODCLR As Variant
Dim TALLE As= Variant
ActiveCell.Value
with:
With ActiveCell
CODART = concatRange.Offset(0, 2).Value
CODCLR = concatRange.Offset(0, 1).Value
TALLE = concatRange.Offset(0, 12).Value
End With
Minimize the Use of Loops: Avoid using loops when not necessary. In your case, you can directly work with ranges and cells without the need for a loop.
Replace:
While ActiveCell.Value <> "" And ventasSheetActiveCell.Range("B"Value &<> ventasSheet.Rows.Count).EndVal(xlUpL).Offset(1, 0)And ActiveCell.Value =<> CODARTL
ventasSheet.Range("B" & ventasSheet.Rows.Count).End(xlUp)ActiveCell.Offset(01, 10).Value = CODCLRSelect
Wend
with:
On Error Resume Next
Set foundCell = ventasSheetconcatSheet.RangeColumns("B" & ventasSheet.Rows.Count1).EndFind(xlUp).OffsetVal(0L), 2LookIn:=xlValues).Value
On =Error TALLEGoTo 0
If Not foundCell Is EndNothing If
ERR1:Then
Application.ScreenUpdating' =Your Truelogic here
End SubIf
FewThese suggestions aim to reduce the reliance on selecting cells and looping through them, which should improve the performance of your code. Adjustments may be needed based on your specific requirements.
Tips: