You did not say how you tested, what results you got, and how those results differed from what you expected, so we can only guess why you think your code is incorrect. I'd suggest:
RewriteCond %{HTTP_REFERER} .
RewriteCond %{HTTP_REFERER} !^http://sub\.example\.com
RewriteRule ^(([^.]+\.)+(s?html?|php[0-9]{0,2}))?$ http://sub.example.com/folder/file.htm [R=302,L]
"IF the referer is sub.example.com, sub.example.com., sub.example.com:80, sub.example.com,:80, or blank (these are all perfectly-valid HTTP Referrer values),
AND if the request is for a .shtml, .shtm, .html, .htm, .php, or .php5 'page' or a blank URL-path indicating your 'home page',
THEN redirect to sub.example.com/folder/file.htm"
Jim