I need some help to make my conde much simpler. I'm starting to code on VBA and build my own scripts and they work properly, sometimes. But they are always tooooo big and much more complicated than it could be.
This is one case that everytime I run the script, Excel crashes. Can someone assist me in making this code much more simple?
Sub Cleaning_Mirexs()
Application.ScreenUpdating = False
Dim UltCel As Range
Dim Mirex As String
Dim Glip As String
Mirex = "S"
Glip = "UP"
Set UltCel = Cells(Rows.Count, 2).End(xlUp)
' Moving Data for treatment
Range("R2").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Range("X2").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Selection.TextToColumns Destination:=Range("X2"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False, _
Semicolon:=False, Comma:=False, Space:=False, Other:=True, OtherChar _
:="-", FieldInfo:=Array(Array(1, 1), Array(2, 1)), TrailingMinusNumbers:=True
' Mirex Formicide Data
Range("$Y2").Select
Do While ActiveCell <> UltCel
If InStr(1, ActiveCell.Text, Mirex) Then
ActiveCell.FormulaR1C1 = ""
ActiveCell.Offset(0, -1).Select
ActiveCell.Clear
ActiveCell.FormulaR1C1 = "IS FORMICIDA MIREX-S" & ActiveCell.Value
ActiveCell.Offset(1, 1).Select
ElseIf ActiveCell.Offset(xlDown) Then
End If
Loop
' Glip Herbicide Data
Range("Y2").Select
Do While ActiveCell <> UltCel
If InStr(1, ActiveCell.Text, Glip) Then
ActiveCell.Formula = ""
ActiveCell.Offset(0, -1).Select
ActiveCell.Clear
ActiveCell.FormulaR1C1 = "HB GLIP-UP" & ActiveCell.Value
ActiveCell.Offset(1, 1).Select
ElseIf ActiveCell.Offset(1, 0).Select Then
End If
Loop
' Light Tractor Data
Range("X2").Select
Do While ActiveCell <> UltCel
If InStr(1, ActiveCell.Text, "Tratores leves") Then
ActiveCell.Clear
ActiveCell.FormulaR1C1 = "Tratores leves" & ActiveCell.Value
ActiveCell.Offset(1, 0).Select
ElseIf ActiveCell.Offset(1, 0).Select Then
End If
Loop
' Heavy Tractor Data
Range("X2").Select
Do While ActiveCell <> UltCel
If InStr(1, ActiveCell.Text, "Tratores pesados") Then
ActiveCell.Clear
ActiveCell.FormulaR1C1 = "Tratores pesados" & ActiveCell.Value
ActiveCell.Offset(1, 0).Select
ElseIf ActiveCell.Offset(1, 0).Select Then
End If
Loop
' back to original place after data treatment
Range("X2").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Range("X2").Select
Selection.PasteSpecial Paste:=xlPasteValues
Application.ScreenUpdating = True
MsgBox "Success!"
End Sub
I would like the code to run everything at once, but they way I wrote the script, feels like, a individual run for each data set.
Well, here it is! Let's have fun :)
Thank you!
Maria