Hi to everyone,
I am new to the forum and to the vba code. I am creating an excel workbook which would automate certain type of routinary calculations.
So far all I wanna do is to add to my workbook a cell conditional value according to a number which I have in a cell (let's say C10).
I created a peice of script which has to delete or insert values and formulas according to the value in cell C12
Why does not work? Excel get blocked and crashes when I run it.
thanks a lot
Luca
I am new to the forum and to the vba code. I am creating an excel workbook which would automate certain type of routinary calculations.
So far all I wanna do is to add to my workbook a cell conditional value according to a number which I have in a cell (let's say C10).
I created a peice of script which has to delete or insert values and formulas according to the value in cell C12
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Application.ScreenUpdating = False
NmrStd = Sheets("Step 1").Range("C10").Value
Select Case NmrStd
Case Is = 2
Selection.Range("D17 : I18").ClearContents
[COLOR=#000000][FONT=inherit]Worksheets[/FONT][/COLOR][COLOR=#666600][FONT=inherit]([/FONT][/COLOR][COLOR=#008800][FONT=inherit]"Step 1"[/FONT][/COLOR][COLOR=#666600][FONT=inherit]).[/FONT][/COLOR][COLOR=#000000][FONT=inherit]Range[/FONT][/COLOR][COLOR=#666600][FONT=inherit]([/FONT][/COLOR][COLOR=#008800][FONT=inherit]"K20"[/FONT][/COLOR][COLOR=#666600][FONT=inherit]).[/FONT][/COLOR][COLOR=#000000][FONT=inherit]Formula[/FONT][/COLOR][COLOR=#000000][FONT=inherit] [/FONT][/COLOR][COLOR=#666600][FONT=inherit]=[/FONT][/COLOR][COLOR=#000000][FONT=inherit] [/FONT][/COLOR][COLOR=#008800][FONT=inherit]"=AVERAGE(I15 : I16)"[/FONT][/COLOR]
[COLOR=#008800][FONT=inherit] [/FONT][/COLOR]
Case Is = 4
Selection.Range("D17 : E18").ClearContents
[COLOR=#000000][FONT=inherit]Worksheets[/FONT][/COLOR][COLOR=#666600][FONT=inherit]([/FONT][/COLOR][COLOR=#008800][FONT=inherit]"Step 1"[/FONT][/COLOR][COLOR=#666600][FONT=inherit]).[/FONT][/COLOR][COLOR=#000000][FONT=inherit]Range[/FONT][/COLOR][COLOR=#666600][FONT=inherit]([/FONT][/COLOR][COLOR=#008800][FONT=inherit]"D17"[/FONT][/COLOR][COLOR=#666600][FONT=inherit]).[/FONT][/COLOR][COLOR=#000000][FONT=inherit]Value[/FONT][/COLOR][COLOR=#000000][FONT=inherit] [/FONT][/COLOR][COLOR=#666600][FONT=inherit]=[/FONT][/COLOR][COLOR=#000000][FONT=inherit] [/FONT][/COLOR][COLOR=#008800][FONT=inherit]"STD1"
[/FONT][/COLOR] [COLOR=#000000][FONT=inherit]Worksheets[/FONT][/COLOR][COLOR=#666600][FONT=inherit]([/FONT][/COLOR][COLOR=#008800][FONT=inherit]"Step 1"[/FONT][/COLOR][COLOR=#666600][FONT=inherit]).[/FONT][/COLOR][COLOR=#000000][FONT=inherit]Range[/FONT][/COLOR][COLOR=#666600][FONT=inherit]([/FONT][/COLOR][COLOR=#008800][FONT=inherit]"D18"[/FONT][/COLOR][COLOR=#666600][FONT=inherit]).[/FONT][/COLOR][FONT=inherit][COLOR=#000000]VAlue [/COLOR][/FONT][COLOR=#666600][FONT=inherit]=[/FONT][/COLOR][COLOR=#000000][FONT=inherit] [/FONT][/COLOR][COLOR=#008800][FONT=inherit]"STD2"
[COLOR=#000000][FONT=inherit] Worksheets[/FONT][/COLOR][COLOR=#666600][FONT=inherit]([/FONT][/COLOR][FONT=inherit]"Step 1"[/FONT][COLOR=#666600][FONT=inherit]).[/FONT][/COLOR][COLOR=#000000][FONT=inherit]Range[/FONT][/COLOR][COLOR=#666600][FONT=inherit]([/FONT][/COLOR][FONT=inherit]"I17"[/FONT][COLOR=#666600][FONT=inherit]).[/FONT][/COLOR][COLOR=#000000][FONT=inherit]Formula[/FONT][/COLOR][COLOR=#000000][FONT=inherit] [/FONT][/COLOR][COLOR=#666600][FONT=inherit]=[/FONT][/COLOR][COLOR=#000000][FONT=inherit] [/FONT][/COLOR][FONT=inherit]"=E17/(F17*G17*H17)"[/FONT]
[COLOR=#000000][FONT=inherit] [FONT=inherit]Worksheets[/FONT][COLOR=#666600][FONT=inherit]([/FONT][/COLOR][COLOR=#008800][FONT=inherit]"Step 1"[/FONT][/COLOR][COLOR=#666600][FONT=inherit]).[/FONT][/COLOR][FONT=inherit]Range[/FONT][COLOR=#666600][FONT=inherit]([/FONT][/COLOR][COLOR=#008800][FONT=inherit]"I18"[/FONT][/COLOR][COLOR=#666600][FONT=inherit]).[/FONT][/COLOR][FONT=inherit]Formula[/FONT][FONT=inherit] [/FONT][COLOR=#666600][FONT=inherit]=[/FONT][/COLOR][FONT=inherit] [/FONT][COLOR=#008800][FONT=inherit]"=E18/(F18*G18*H18)"[/FONT][/COLOR]
Worksheets[/FONT][/COLOR][COLOR=#666600][FONT=inherit]([/FONT][/COLOR][FONT=inherit]"Step 1"[/FONT][COLOR=#666600][FONT=inherit]).[/FONT][/COLOR][COLOR=#000000][FONT=inherit]Range[/FONT][/COLOR][COLOR=#666600][FONT=inherit]("[/FONT][/COLOR][FONT=inherit]G17"[/FONT][COLOR=#666600][FONT=inherit]).[/FONT][/COLOR][COLOR=#000000][FONT=inherit]Formula[/FONT][/COLOR][COLOR=#000000][FONT=inherit] [/FONT][/COLOR][COLOR=#666600][FONT=inherit]= [/FONT][/COLOR][COLOR=#000000][FONT=inherit]"=[/FONT][/COLOR]SE(E17>0;CERCA.VERT(F2;Prodotti!A3:S37;19;FALSO);"")"
[/FONT][/COLOR] [COLOR=#000000][FONT=inherit]Worksheets[/FONT][/COLOR][COLOR=#666600][FONT=inherit]([/FONT][/COLOR][COLOR=#008800][FONT=inherit]"Step 1"[/FONT][/COLOR][COLOR=#666600][FONT=inherit]).[/FONT][/COLOR][COLOR=#000000][FONT=inherit]Range[/FONT][/COLOR][COLOR=#666600][FONT=inherit]("[/FONT][/COLOR][COLOR=#008800][FONT=inherit]G18"[/FONT][/COLOR][COLOR=#666600][FONT=inherit]).[/FONT][/COLOR][COLOR=#000000][FONT=inherit]Formula[/FONT][/COLOR][COLOR=#000000][FONT=inherit] [/FONT][/COLOR][COLOR=#666600][FONT=inherit]=[/FONT][/COLOR][COLOR=#000000][FONT=inherit] "=[/FONT][/COLOR][COLOR=#008800]SE(E17>0;CERCA.VERT(F2;Prodotti!A3:S37;19;FALSO);"")"[/COLOR]
[COLOR=#000000][FONT=inherit]Worksheets[/FONT][/COLOR][COLOR=#666600][FONT=inherit]([/FONT][/COLOR][COLOR=#008800][FONT=inherit]"Step 1"[/FONT][/COLOR][COLOR=#666600][FONT=inherit]).[/FONT][/COLOR][COLOR=#000000][FONT=inherit]Range[/FONT][/COLOR][COLOR=#666600][FONT=inherit]([/FONT][/COLOR][COLOR=#008800][FONT=inherit]"K20"[/FONT][/COLOR][COLOR=#666600][FONT=inherit]).[/FONT][/COLOR][COLOR=#000000][FONT=inherit]Formula[/FONT][/COLOR][COLOR=#000000][FONT=inherit] [/FONT][/COLOR][COLOR=#666600][FONT=inherit]=[/FONT][/COLOR][COLOR=#000000][FONT=inherit] [/FONT][/COLOR][COLOR=#008800][FONT=inherit]"=AVERAGE(I15 : I18)"[/FONT][/COLOR]
End Select
Application.ScreenUpdating = True
End Sub
Why does not work? Excel get blocked and crashes when I run it.
thanks a lot
Luca