I am looking for help in a code that is complicating me a lot since I must use (at least I think so) the Range method. Find , which I have not managed to know how it works.
What I need is a code with which you can enter new blank rows in an excel sheet, this row must be entered if certain conditions are met.
I have a excel sheet that contains "Subchapters" and "Items" , there is a possibility that new Items should be created and for that the user has the following form:
The code so far reads the data from the field "Insert the Name of the Subchapter" and it will look for the sheet "BDusuario1"
Now what follows (and is the part where I need help) is that once the search object is located the macro is due:
Note: Codes can only arrive until they end at 99 for example 4011099
, if that limit was reached and no space was found to add the new item a message should be displayed informing you.
I will attach a basic copy of the original file, since I can not send the original, but I hope it is enough for them to work. The important fields for this macro are the ones that I enclose in blue and I highlight in yellow, the rest can ignore it.
I hope you have managed to make me understand, if you need more information or more clarity on something I will gladly try to give them to you.
This is the part of the code where I need help, put comments on what each line should do for what I hope is better clarity.
Cod = ActiveCell.Offset(0, -2) 'Aca intento hacer una vez encontrado el dato de la variable "nomSubc" se mueva 2 filas a la izquierda y lea un código que allí se encuentra
'''Cod = a.Cells(fila, "A").Value
'-------------------------
For itm = 1 To 99
Cod1 = ActiveCell.Value 'en esta parte lo que quiero es que una vez sea lea ese código se guarde en una variable
Cod1 = Cod1 + 1 'y se le sume 1
'---------------------------
Cod2 = ActiveCell.Offset(1, 0) 'Aca lo que busco que se lea en código que esta de bajo del que se guardo en la variable "Cod1"
'---------------------------
If Cod1 <> Cod2 Then 'En estás lineas se debe hacer una comparacion,
ActiveCell.EntireRow.Insert 'Si son diferentes se debe crear una fila vacia en la mitad de Cod1 y Cod2
'ActiveCell.Offset(2, 0) 'Si Cod1 y Cod2 son iguales Cod1 debe pasar a leer Cod2 y Cod2 debe pasar a leer el código de abajo
Else
MsgBox "Error", vbExclamation
End If
Next itm
End If
End Sub