Afternoon everyone!!
I recently joined this forum to better hone my excel skills. Although I am not a new user of excel by any means but I am to the VBA/MACRO world. I am currently reviewing our quality assurance and control documents, implementing formulas & code to simplify things for the guys in the field . As well as minimize the amount of mistakes I am seeing in these documents when filled out. I have a section of code I would like some feed back on, and if there is a better way to write this. I have also included a screen shot of what the formatting looks like. If this is about the best way to write this code, is this pushing the limits are as far processing capability is concerned? I am noticing that it does take a second or two to run through this code when you change your spec in cell F9. This is currently done on Excel2013, I was running 2016 but was having issues with new updates crashing and will be returning back to Excel 2016 once my IT department sorts the issues out. Is there more or better coding options in 2016 compared to 2013? Or is it pretty much the same language and options?
Thanks guys for any and all input.
I recently joined this forum to better hone my excel skills. Although I am not a new user of excel by any means but I am to the VBA/MACRO world. I am currently reviewing our quality assurance and control documents, implementing formulas & code to simplify things for the guys in the field . As well as minimize the amount of mistakes I am seeing in these documents when filled out. I have a section of code I would like some feed back on, and if there is a better way to write this. I have also included a screen shot of what the formatting looks like. If this is about the best way to write this code, is this pushing the limits are as far processing capability is concerned? I am noticing that it does take a second or two to run through this code when you change your spec in cell F9. This is currently done on Excel2013, I was running 2016 but was having issues with new updates crashing and will be returning back to Excel 2016 once my IT department sorts the issues out. Is there more or better coding options in 2016 compared to 2013? Or is it pretty much the same language and options?
VBA Code:
Sub Worksheet_SelectionChange(ByVal Target As Range)
'PVF / Tubing Specs Based on Piping Class
Sheet1.Unprotect "8unch2015@"
If Range("f9") = False Then
Range("f8,f10,f11,f12,f13,y9,y10,y11,y13,AL13,y12") = ""
Sheet1.Protect "8unch2015@"
End
ElseIf Range("f9") = "A 150" Then
Range("f8") = "Hydrocarbon, unprocessed produced fluids, produced water, slop, fuel gas, flare, drain, gycol/water and Instrument Air"
Range("f10") = "1/2 - 2, Sch 80(XS), Scrd/SW, A106 GrB"
Range("f11") = "1/2 - 2, 3000#, Scrd/SW, A105N"
Range("f12") = "1960 KPag (285 psig)"
Range("f13") = "2940 KPag (428 psig)"
Range("y9") = "1/2 - 2, Sch 80, Srcd or PE, A106 GrB"
Range("y10") = "1/2 - 2, 3000#, Srcd or PE, A105N"
Range("y11") = "1/2 - 2, Scrd/SW, 2000#, A105N/A216 WCB Body"
Range("y13") = "3/8 x 0.035 A269 Gr316SS"
Range("AL13") = "1/2 x 0.049 A269 Gr316SS"
Range("ar8") = "ASME B31.3-(2018)"
Range("y12") = "1/2 - 3/4 10,000 PSI, Scrd, SS316"
ElseIf Range("f9") = "AC 150" Then
Range("f8") = "Hydrocarbon, unprocessed produced fluids, produced water, slop, fuel gas, flare, drain, gycol/water"
Range("f10") = "1/2 - 2, Sch 80, Scrd/SW, A106 GrB"
Range("f11") = "/2 - 2, 3000#, Scrd/SW, A105N"
Range("f12") = "1900 KPag (275 psig)"
Range("f13") = "2850 KPag (413 psig)"
Range("y9") = "1/2 - 2, Sch 80, Srcd or PE, A106 GrB"
Range("y10") = "1/2 - 2, 3000#, Srcd or PE, A105N"
Range("y11") = "1/2 - 2, Scrd/SW, 2000#, A105N/A216 WCB Body"
Range("y13") = "3/8 x 0.035 A269 Gr316SS"
Range("AL13") = "1/2 x 0.035 A269 Gr316SS"
Range("ar8") = "ACSA Z662-19"
Range("y12") = "1/2 - 3/4 10,000 PSI, Scrd, SS316"
ElseIf Range("f9") = "AI 150" Then
Range("f8") = "Utility & Instrument Air"
Range("f10") = "1/2 - 2, Sch 80(XS), Scrd, A106 GrB or PE Galvanized"
Range("f11") = "3/4 - 2, 2000#, Scrd, A105N Galvanized"
Range("f12") = "1033 KPag (150 psig)"
Range("f13") = "1033 KPag (150 psig)"
Range("y9") = "3/4 - 2, Match Pipe, Scrd, A53 BrB or Galvanized"
Range("y10") = "3/4 - 2, 2000#, Scrd, A105N or A234 WPB Galvanized"
Range("y11") = "1/2 - 2, Scrd/SW, 2000#, A105N/A216 WCB Body"
Range("y13") = "3/8 x 0.035 A269 Gr316SS"
Range("AL13") = "1/2x 0.035 A269 Gr316SS"
Range("ar8") = "ASME B31.3-(2018)"
Range("y12") = "1/2 - 3/4 10,000 PSI, Scrd, SS316"
ElseIf Range("f9") = "AL 150" Then
Range("f10") = "1/2 - 2 sch80 A333"
Range("f11") = "1/2 - 2 3000# A350 LF2"
Range("y9") = "1/2 - 2 sch80 A333"
Range("y10") = "1/2 - 2 3000# A350 LF2"
Range("y11") = "1/2 - 2 2000# A350 LF2"
Range("y13") = "3/8 x 0.035"
Range("AL13") = "1/2 x 0.049"
Range("y12") = "10,000 PSI SS316"
ElseIf Range("f9") = "ALS 150" Then
Range("f10") = "1/2 xxs, 3/4 - 1 1/2 sch160, 2 sch80 A333"
Range("f11") = "1/2 - 1 1/2 3000#, 2 sch80 A350 LF2"
Range("y9") = "1/2 xxs, 3/4 - 1 1/2 sch160, 2 sch80 A333"
Range("y10") = "1/2 - 2 3000# A350 LF2"
Range("y11") = "1/2 - 1 1/2 2000#, 2 150# A350 LF2"
Range("y13") = "3/8 x 0.035"
Range("AL13") = "1/2 x 0.049"
Range("y12") = "10,000 PSI SS316"
ElseIf Range("f9") = "ALSC" Then
Range("f10") = "1/2 - 1 1/2 sch160, 2 sch40 A106"
Range("f11") = "1/2 - 1 1/2 3000#, 2 sch40 A105N"
Range("y9") = "1/2 - 1 1/2 sch160 A106"
Range("y10") = "1/2 - 2 3000# A105N"
Range("y11") = "1/2 - 1 1/2 2000# A105N"
Range("y13") = "3/8 x 0.035"
Range("AL13") = "1/2 x 0.035"
Range("y12") = "10,000 PSI SS316"
ElseIf Range("f9") = "AS" Then
Range("f10") = "1/2 xxs, 3/4 - 1 1/2 sch160 A106"
Range("f11") = "1/2 - 1 1/2 3000# A105N"
Range("y9") = "1/2 xxs, 3/4 - 1 1/2 sch160 A106"
Range("y10") = "1/2 - 2 3000# A105N"
Range("y11") = "1/2 - 1 1/2 2000# A105N"
Range("y13") = "3/8 x 0.035"
Range("AL13") = "1/2 x 0.049"
Range("y12") = "10,000 PSI SS316"
ElseIf Range("f9") = "BLS" Then
Range("f10") = "1/2 - 1 1/2 XXS A333"
Range("f11") = "1/2 - 1 1/2 3000# A105N LF2"
Range("y9") = "1/2 - 1 1/2 XXS A333"
Range("y10") = "3/4 - 2 3000# A350 LF2"
Range("y11") = "1/2 2000# A350 LF2"
Range("y13") = "3/8 x 0.035"
Range("AL13") = "1/2 x 0.049"
Range("y12") = "10,000 PSI SS316"
ElseIf Range("f9") = "BS" Then
Range("f10") = "1/2 - 1 1/2 XXS A106"
Range("f11") = "1/2 - 1 1/2 3000# A105N"
Range("y9") = "1/2 - 1 1/2 XXS A106"
Range("y10") = "1/2 - 2 3000# A105N"
Range("y11") = "1/2 2000# A105N"
Range("y13") = "3/8 x 0.035"
Range("AL13") = "1/2 x 0.049"
Range("y12") = "10,000 PSI SS316"
ElseIf Range("f9") = "C" Then
Range("f10") = "1/2 - 2 sch160 A106"
Range("f11") = "1/2 - 2 3000# A105N"
Range("y9") = "1/2 - 2 sch160 A106"
Range("y10") = "1/2 - 2 3000# A105N"
Range("y11") = "1/2 - 2 3000# A105N"
Range("y13") = "3/8 x 0.035"
Range("AL13") = "1/2 x 0.049"
Range("y12") = "10,000 PSI SS316"
ElseIf Range("f9") = "CL 600" Then
Range("f10") = "1/2 - 2 sch160 A333"
Range("f11") = "1/2 - 2 3000# A350 LF2"
Range("y9") = "1/2 - 2 sch160 A333"
Range("y10") = "1/2 - 2 3000# A350 LF2"
Range("y11") = "1/2 - 2 3000# A350 LF2"
Range("y13") = "3/8 x 0.035"
Range("AL13") = "1/2 x 0.049"
Range("y12") = "10,000 PSI SS316"
ElseIf Range("f9") = "CLS 600" Then
Range("f10") = "1/2 - 1 1/2 XXS A333"
Range("f11") = "1/2 - 1 1/2 6000# A350 LF2"
Range("y9") = "1/2 - 1 1/2 XXS A333"
Range("y10") = "3/4 -2 6000# A350 LF2"
Range("y11") = "1/2 3000# A350 LF2"
Range("y13") = "3/8 x 0.035"
Range("AL13") = "1/2 x 0.049"
Range("y12") = "10,000 PSI SS316"
ElseIf Range("f9") = "CLSC" Then
Range("f10") = "1/2 - 1 1/2 sch160 A106"
Range("f11") = "1/2 - 1 1/2 3000# A105N"
Range("y9") = "1/2 - 1 1/2 sch160 A106"
Range("y10") = "1/2 - 2 3000# A105N"
Range("y11") = "1/2 - 1 1/2 3000# A105N"
Range("y13") = "3/8 x 0.035"
Range("AL13") = "1/2 x 0.035"
Range("y12") = "10,000 PSI SS316"
ElseIf Range("f9") = "CLSZ" Then
Range("f10") = "1/2 - 1 1/2 sch160"
Range("f11") = "1/2 - 1 1/2 3000#"
Range("y9") = "1/2 - 1 1/2 sch160"
Range("y10") = "1/2 - 2 3000#"
Range("y11") = "1/2 - 1 1/2 3000#"
Range("y13") = ""
Range("AL13") = ""
Range("y12") = "10,000 PSI SS316"
ElseIf Range("f9") = "CS" Then
Range("f10") = "1/2 - 1 1/2 XXS A106"
Range("f11") = "1/2 - 1 1/2 6000# A105N"
Range("y9") = "1/2 - 1 1/2 XXS A106"
Range("y10") = "1/2 - 1 1/2 6000# A106"
Range("y11") = "1/2 3000# A105N"
Range("y13") = "3/8 x 0.049"
Range("AL13") = "1/2 x 0.049"
Range("y12") = "10,000 PSI SS316"
ElseIf Range("f9") = "DS" Then
Range("f10") = "1/2 - 3/4 XXS A106"
Range("f11") = "1/2 - 3/4 6000# A105N"
Range("y9") = "1/2 - 3/4 XXS A106"
Range("y10") = "1/2 - 3/4 6000# A105N"
Range("y11") = "1/2 6000# A105N"
Range("y13") = "3/8 x 0.065"
Range("AL13") = "1/2 x 0.065"
Range("y12") = "10,000 PSI SS316"
ElseIf Range("f9") = "EL" Then
Range("f10") = "1/2 - 1 1/2 XXS A333"
Range("f11") = "1/2 - 1 1/2 6000# A350 LF2"
Range("y9") = "1/2 - 1 1/2 XXS A333"
Range("y10") = "1/2 - 2 6000# A350 LF2"
Range("y11") = "1/2 - 1 1/2 6000# A350 LF2"
Range("y13") = "3/8 x 0.065"
Range("AL13") = "1/2 x 0.065"
Range("y12") = "10,000 PSI SS316"
ElseIf Range("f9") = "ELS 1500" Then
Range("f10") = "1/2 - 3/4 XXS A333"
Range("f11") = "1/2 - 3/4 6000# A350 LF2"
Range("y9") = "1/2 - 3/4 XXS A333 "
Range("y10") = "1/2 - 3/4 6000# A350 LF2"
Range("y11") = "1/2 6000# A350 LF2"
Range("y13") = "3/8 x 0.065"
Range("AL13") = "1/2 x 0.065"
Range("y12") = "10,000 PSI SS316"
ElseIf Range("f9") = "ELSC" Then
Range("f10") = "1/2 - 1 XXS A106"
Range("f11") = "1/2 - 1 6000# A105N"
Range("y9") = "1/2 - 1 XXS A106"
Range("y10") = "1/2 - 1 6000# A105N"
Range("y11") = "1/2 - 1 6000# A105N"
Range("y13") = "3/8 x 0.065"
Range("AL13") = "1/2 x 0.065"
Range("y12") = "10,000 PSI SS316"
ElseIf Range("f9") = "FLS" Then
Range("f10") = "1/2 - 3/4 XXS A333"
Range("f11") = "1/2 - 3/4 6000# A350 LF2"
Range("y9") = "1/2 - 1 XXS A333"
Range("y10") = "1/2 - 3/4 6000# A350 LF2"
Range("y11") = "1/2 A350 LF2"
Range("y13") = "3/8 X 0.065"
Range("AL13") = "1/2 X 0.083"
Range("y12") = "10,000 PSI SS316"
ElseIf Range("f9") = "SFLS 150" Then
Range("f10") = "3/4 - 1 1/2 sch80 A333"
Range("f11") = "3/4 - 1 1/2 2000# A350 LF2"
Range("y9") = "3/4 - 1 1/2 sch80 A333"
Range("y10") = "3/4 - 2 2000# A350 LF2"
Range("y11") = "3/4 - 2 2000# A350 LF2"
Range("y13") = "3/8 x 0.035"
Range("AL13") = "3/8 x 0.035"
Range("y12") = "3000 PSI"
ElseIf Range("f9") = "SRLS 600 (PN100)" Then
Range("f10") = "3/4 - 1 1/2 sch160 A333"
Range("f11") = "3/4 - 1 1/2 2000# A350 LF2"
Range("y9") = "3/4 - 1 1/2 sch80 A333"
Range("y10") = "3/4 - 2 2000# A350 LF2"
Range("y11") = "3/4 - 2 2000# A350 LF2"
Range("y13") = "3/8 x 0.035"
Range("AL13") = "1/2 x 0.049"
Range("y12") = "3000 PSI"
End If
Cancel = True
Application.EnableEvents = True
Sheet1.Protect "8unch2015@"
End Sub
Thanks guys for any and all input.
Last edited by a moderator: