I am using this code to run a macro everytime a cell in column H changes.
The macro I am trying to use is supposed to make cells in column 'I' change in regards to column H and output a statement in the respective 'I' cell. (as in, if H20 = "t2", then I = "statement).
But, as you can see, the formula I am using is way too long and the code gives me an error (I actually need more statements). To be honest I am not very good at VBA and I don't know how to make it work.
The original code I used to help myself was this:
Which actually works, it adds 1 to every cell in 'I' that isn't empty.
Could any of you guys help me with either:
Thank you very much. ^^
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("H:H")) Is Nothing Then
Call DefMacro
End If
End Sub
The macro I am trying to use is supposed to make cells in column 'I' change in regards to column H and output a statement in the respective 'I' cell. (as in, if H20 = "t2", then I = "statement).
Code:
Sub DefMacro()
Range("I2").Formula = "=IF(H1="T1","COBRE EXPUESTO EN VENAS",IF(H1="T2","CONDUCTORES INVERTIDOS",IF(H1="T3","ORIFICIO TAPADO EN TABLILLA",IF(H1="T4","PORO EN SOLDADURA",IF(H1="T5","SELLADOR FALTANTE EN TABLILLA",IF(H1="T6","EXCESO DE FLUX EN SOLDADURA",IF(H1="T7","EXCESO DE SELLADOR",IF(H1="T8","FALTA DE SOLDADURA",IF(H1="T9","HILILLOS DAÑADOS",IF(H1="T10","JAULA DE PAJARO",IF(H1="T11","ORIFICIO TAPADO CON SELLADOR",IF(H1="T12","PORO EN PASTA",IF(H1="T13","PORO EN SOLDADURA",IF(H1="T14","SELLADOR FALTANTE",IF(H1="T15","SOLDADURA ALTA",IF(H1="T16","SOLDADURA CORTA",IF(H1="T17","SOLDADURA MALFORMADA",IF(H1="R1","CINTA DE ROTOR DAÑADA",IF(H1="R2","CINTA DE ROTOR DESPRENDIDA",IF(H1="R3","CINTA DE ROTOR CORTA (ALTURA)",IF(H1="R4","CUBIERTA METALICA FUERA DE SPEC",IF(H1="R5","FALTA DE PASTA EN MAGNETO",IF(H1="R6","FLECHA DAÑADA",IF(H1="R7","FLECHA CON REBABA",IF(H1="R8","MAGNETO AGRIETADO",IF(H1="R9","MAGNETO DAÑADO (LIJADO)",IF(H1="R10","MAGNETO MAQUINADO FUERA DE SPEC",IF(H1="R11","MAGNETO QUEBRADO"," & _
"IF(H1="R12","POLARIDAD",IF(H1="R13","PORO EN CINTA DE ROTOR","cero"))))))))))))))))))))))))))))))"
Range("I2", "I" & Cells(Rows.Count, 1).End(xlUp).Row).FillDown
End Sub
But, as you can see, the formula I am using is way too long and the code gives me an error (I actually need more statements). To be honest I am not very good at VBA and I don't know how to make it work.
The original code I used to help myself was this:
Code:
Sub DefMacro()
Range("I2").Formula = "=$J3+1"
Range("I2", "I" & Cells(Rows.Count, 1).End(xlUp).Row).FillDown
End Sub
Which actually works, it adds 1 to every cell in 'I' that isn't empty.
Could any of you guys help me with either:
- Change the formula to a function (select case, etc)?
- Make the formula work with some kind of line break or something?
- Tell me if 'H1' will make the formula not work with each H cell by row as I intend it to and if I should change it to something more general?
- Provide another method to achieve the results or any other suggestion?
Thank you very much. ^^