Ideally. with the aid of retrospectroscope, the British should have rounded up just about every 40mm Bofors gun in British commonwealth (around 100?) and mounted them on the PoW and Repulse in Oct of 1941 before sail the ships to the far east after pulling any less than main battery guns needed to allow for deck space and weight.
Production of the hand worked land service single air cooled Bofors had begun in Britain in early 1939. 1,233 were produced in 1940 and 2,712 in 1941. But with the Army having virtually no AA defences it had priority. By the end of 1941 some 136 were in RN hands mostly with the DEMS (but one was on PoW - quarterdeck mount). It would be into 1942 before twin water-cooled Hazemeyer mounts would begin to turn up in RN service.
That all depends on ammunition used.The 2pdr pom-pom was an individual ship defensive weapon. It didn't have the range to engage aircraft that were attacking a neighboring ship as a general rule. The Bofors gun had more range and were more useful.
Navweaps gives the 2pdr Mk.VIII with High Velocity rounds, the main type used in WW2, as having a max range of 5,000 yards and an effective range of 1,700 yards. While it credits the Bofors with a greater range it notes that most British ammunition types were designed to self destruct at 3,000-3,500 yards (US rounds 4,000-5,000 yards) to prevent friendly fire accidents.
But the Japanese Rikko units trained to drop their torpedoes at 1,000m but against Force Z pressed home to 500-800m.