2017-10-06 22 views
0

こんにちは仲間のプログラマー!ExcelからVBAコードへの式

私はVBAに新しく、既存のExcelテンプレートで大きな変更を加えなければならない... 今、私の問題は、Excelから式をエクスポートしようとしている間に(それは後でボタンをクリックして作業する)これは、作業を行いますが、私は構文エラーを取得

Sub InsertTodaysDate() 
    Sheets("Sheet1").Select 
    Range("A1").Select 
     Selection.FormulaLocal = "=WENN(LÄNGE('Step 2 - Add Contact Informatio'!A4)>100;""too many characters"";"" 
WENN('Step 2 - Add Contact Informatio'!A4="""";""Email is mandatory""; 
WENN(ISTZAHL(FINDEN(""!"";'Step 2 - Add Contact Informatio'!A4)); 
""special characters are not allowed""; 
WENN(ISTZAHL(FINDEN(""*"";'Step 2 - Add Contact Informatio'!A4)); 
""special characters are not allowed""; 
WENN(ISTZAHL(FINDEN("":"";'Step 2 - Add Contact Informatio'!A4)); 
""special characters are not allowed""; 
WENN(ISTZAHL(FINDEN(""="";'Step 2 - Add Contact Informatio'!A4)); 
""special characters are not allowed""; 
WENN(ISTZAHL(FINDEN(""`"";'Step 2 - Add Contact Informatio'!A4)); 
""special characters are not allowed""; 
WENN(ISTZAHL(FINDEN(""\""; 
'Step 2 - Add Contact Informatio'!A4)); 
""special characters are not allowed""; 
WENN(ISTZAHL(FINDEN(""]"";'Step 2 - Add Contact Informatio'!A4)); 
""special characters are not allowed""; 
WENN(ISTZAHL(FINDEN(""["";'Step 2 - Add Contact Informatio'!A4)); 
""special characters are not allowed""; 
WENN(ISTZAHL(FINDEN(""}"";'Step 2 - Add Contact Informatio'!A4)); 
""special characters are not allowed""; 
WENN(ISTZAHL(FINDEN(""{"";'Step 2 - Add Contact Informatio'!A4)); 
""special characters are not allowed""; 
WENN(ISTZAHL(FINDEN(""´"";'Step 2 - Add Contact Informatio'!A4)); 
""special characters are not allowed""; 
WENN(ISTZAHL(FINDEN(""?"";'Step 2 - Add Contact Informatio'!A4)); 
""special characters are not allowed"";WENN(ISTZAHL(FINDEN("")""; 
'Step 2 - Add Contact Informatio'!A4));""special characters are not allowed""; 
WENN(ISTZAHL(FINDEN(""("";'Step 2 - Add Contact Informatio'!A4)); 
""special characters are not allowed"";WENN(ISTZAHL(FINDEN(""/"";'Step 2 - Add Contact Informatio'!A4));""special characters are not allowed""; 
WENN(ISTZAHL(FINDEN(""&"";'Step 2 - Add Contact Informatio'!A4)); 
""special characters are not allowed""; 
WENN(ISTZAHL(FINDEN(""%"";'Step 2 - Add Contact Informatio'!A4)); 
""special characters are not allowed""; 
WENN(ISTZAHL(FINDEN(""$"";'Step 2 - Add Contact Informatio'!A4)); 
""special characters are not allowed""; 
WENN(ISTZAHL(FINDEN(""§"";'Step 2 - Add Contact Informatio'!A4)); 
""special characters are not allowed""; 
WENN(ISTZAHL(FINDEN(""~"";'Step 2 - Add Contact Informatio'!A4)); 
""special characters are not allowed""; 
WENN(ISTZAHL(FINDEN(""“"";'Step 2 - Add Contact Informatio'!A4)); 
""special characters are not allowed""; 
WENN(ISTZAHL(FINDEN(""^"";'Step 2 - Add Contact Informatio'!A4)); 
""special characters are not allowed""; 
WENN(ISTZAHL(FINDEN(""°"";'Step 2 - Add Contact Informatio'!A4)); 
""special characters are not allowed""; 
WENN(ISTZAHL(FINDEN(""<"";'Step 2 - Add Contact Informatio'!A4)); 
""special characters are not allowed""; 
WENN(ISTZAHL(FINDEN("" "";'Step 2 - Add Contact Informatio'!A4)); 
""spaces are not allowed""; 
WENN(ISTZAHL(FINDEN(""#"";'Step 2 - Add Contact Informatio'!A4)); 
""special characters are not allowed""; 
WENN(ISTZAHL(FINDEN(""'"";'Step 2 - Add Contact Informatio'!A4)); 
""special characters are not allowed""; 
WENN(ISTZAHL(FINDEN("","";'Step 2 - Add Contact Informatio'!A4)); 
""special characters are not allowed""; 
WENN(ISTZAHL(FINDEN("">"";'Step 2 - Add Contact Informatio'!A4));""special characters are not allowed""; 
WENN(ISTFEHLER(D8);""error"";WENN(D8=FALSCH;""error"";""ok"")))))))))))))))))))))))))))))))))" 
End Sub 

を私の悲しげに大きな式を挿入するときに、私も\「「\と」」脱出しようとした

Sub InsertTodaysDate() 
    ' This macro will put today's date in cell A1 on Sheet1 
    Sheets("Sheet1").Select 
    Range("A1").Select 
    Selection.Formula = "=text(now(),""mmm dd yyyy"")" 
    Selection.Columns.AutoFit 
End Sub 

:この簡単な手順を使用することができませんしかし、それはちょうど式の半分のために働いた。誰が問題が何であるか知っていますか?

+0

なぜこのような長い式が必要ですか?間違いなく良い方法があります。おそらくそれ以上の質問で始まる** codereview.stackexchange ** – CallumDA

+0

@CallumDA私の上司はそれが以前に働いていたようで、彼らはそれを使い続けたいと思われるからです。 –

+0

私は理解できます - あなたの上司が 'しかし、より良いソリューションにオープン! – CallumDA

答えて

0

私は本当にあなたの助けをいただきありがとうございます、悲しいうちにそれらのどれも働いていません。しかし、私は上司に正規表現を使うよう説得することができました。おかげさまで、@ u8itあなたのアプローチはうまくいきましたが、答えとしてマークする方法がわかりません

0

FormulaLocalからFormulaに変換して、それを「通常の」VBAに入れてみましたが、少なくとも私の端ではうまくいくようです。私は別々の行にそれぞれIFを置いていただろうが、その後には_のそれは怒っている。 (私は関数のいずれかを誤訳した場合、私に知らせて!)

Sub InsertTodaysDate() 

Sheets("Sheet1").Select 
Range("A1").Select 

Selection.Formula = _ 
"=IF(LEN('Step 2 - Add Contact Informatio'!A4)>100," & """" & "too many characters" & """" & "," & _ 
"IF('Step 2 - Add Contact Informatio'!A4=" & """" & """" & "," & """" & "Email is mandatory" & """" & "," & _ 
"IF(NOT(ISERROR(SEARCH(" & """" & "!" & """" & ",'Step 2 - Add Contact Informatio'!A4)))," & """" & "special characters are not allowed" & """" & "," & "IF(NOT(ISERROR(SEARCH(" & """" & "~*" & """" & ",'Step 2 - Add Contact Informatio'!A4)))," & """" & "special characters are not allowed" & """" & "," & _ 
"IF(NOT(ISERROR(SEARCH(" & """" & ":" & """" & ",'Step 2 - Add Contact Informatio'!A4)))," & """" & "special characters are not allowed" & """" & "," & "IF(NOT(ISERROR(SEARCH(" & """" & "=" & """" & ",'Step 2 - Add Contact Informatio'!A4)))," & """" & "special characters are not allowed" & """" & "," & _ 
"IF(NOT(ISERROR(SEARCH(" & """" & "`" & """" & ",'Step 2 - Add Contact Informatio'!A4)))," & """" & "special characters are not allowed" & """" & "," & "IF(NOT(ISERROR(SEARCH(" & """" & "\" & """" & ",'Step 2 - Add Contact Informatio'!A4)))," & """" & "special characters are not allowed" & """" & "," & _ 
"IF(NOT(ISERROR(SEARCH(" & """" & "]" & """" & ",'Step 2 - Add Contact Informatio'!A4)))," & """" & "special characters are not allowed" & """" & "," & "IF(NOT(ISERROR(SEARCH(" & """" & "[" & """" & ",'Step 2 - Add Contact Informatio'!A4)))," & """" & "special characters are not allowed" & """" & "," & _ 
"IF(NOT(ISERROR(SEARCH(" & """" & "}" & """" & ",'Step 2 - Add Contact Informatio'!A4)))," & """" & "special characters are not allowed" & """" & "," & "IF(NOT(ISERROR(SEARCH(" & """" & "{" & """" & ",'Step 2 - Add Contact Informatio'!A4)))," & """" & "special characters are not allowed" & """" & "," & _ 
"IF(NOT(ISERROR(SEARCH(" & """" & "´" & """" & ",'Step 2 - Add Contact Informatio'!A4)))," & """" & "special characters are not allowed" & """" & "," & "IF(NOT(ISERROR(SEARCH(" & """" & "~?" & """" & ",'Step 2 - Add Contact Informatio'!A4)))," & """" & "special characters are not allowed" & """" & "," & _ 
"IF(NOT(ISERROR(SEARCH(" & """" & ")" & """" & ",'Step 2 - Add Contact Informatio'!A4)))," & """" & "special characters are not allowed" & """" & "," & "IF(NOT(ISERROR(SEARCH(" & """" & "(" & """" & ",'Step 2 - Add Contact Informatio'!A4)))," & """" & "special characters are not allowed" & """" & "," & _ 
"IF(NOT(ISERROR(SEARCH(" & """" & "/" & """" & ",'Step 2 - Add Contact Informatio'!A4)))," & """" & "special characters are not allowed" & """" & "," & "IF(NOT(ISERROR(SEARCH(" & """" & "&" & """" & ",'Step 2 - Add Contact Informatio'!A4)))," & """" & "special characters are not allowed" & """" & "," & _ 
"IF(NOT(ISERROR(SEARCH(" & """" & "%" & """" & ",'Step 2 - Add Contact Informatio'!A4)))," & """" & "special characters are not allowed" & """" & "," & "IF(NOT(ISERROR(SEARCH(" & """" & "$" & """" & ",'Step 2 - Add Contact Informatio'!A4)))," & """" & "special characters are not allowed" & """" & "," & _ 
"IF(NOT(ISERROR(SEARCH(" & """" & "§" & """" & ",'Step 2 - Add Contact Informatio'!A4)))," & """" & "special characters are not allowed" & """" & "," & "IF(NOT(ISERROR(SEARCH(" & """" & "~~" & """" & ",'Step 2 - Add Contact Informatio'!A4)))," & """" & "special characters are not allowed" & """" & "," & _ 
"IF(NOT(ISERROR(SEARCH(" & """" & "“" & """" & ",'Step 2 - Add Contact Informatio'!A4)))," & """" & "special characters are not allowed" & """" & "," & "IF(NOT(ISERROR(SEARCH(" & """" & "^" & """" & ",'Step 2 - Add Contact Informatio'!A4)))," & """" & "special characters are not allowed" & """" & "," & _ 
"IF(NOT(ISERROR(SEARCH(" & """" & "°" & """" & ",'Step 2 - Add Contact Informatio'!A4)))," & """" & "special characters are not allowed" & """" & "," & "IF(NOT(ISERROR(SEARCH(" & """" & "<" & """" & ",'Step 2 - Add Contact Informatio'!A4)))," & """" & "special characters are not allowed" & """" & "," & _ 
"IF(NOT(ISERROR(SEARCH(" & """" & "#" & """" & ",'Step 2 - Add Contact Informatio'!A4)))," & """" & "special characters are not allowed" & """" & "," & "IF(NOT(ISERROR(SEARCH(" & """" & "'" & """" & ",'Step 2 - Add Contact Informatio'!A4)))," & """" & "special characters are not allowed" & """" & "," & _ 
"IF(NOT(ISERROR(SEARCH(" & """" & "," & """" & ",'Step 2 - Add Contact Informatio'!A4)))," & """" & "special characters are not allowed" & """" & "," & "IF(NOT(ISERROR(SEARCH(" & """" & ">" & """" & ",'Step 2 - Add Contact Informatio'!A4)))," & """" & "special characters are not allowed" & """" & "," & _ 
"IF(NOT(ISERROR(SEARCH(" & """" & " " & """" & ",'Step 2 - Add Contact Informatio'!A4)))," & """" & "spaces are not allowed" & """" & "," & _ 
"IF(ISERROR(D8)," & """" & "error" & """" & "," & _ 
"IF(D8=FALSE," & """" & "error" & """" & "," & """" & "ok" & """" & ")))))))))))))))))))))))))))))))))" 

End Sub 

編集:私は?*、および~は、彼らの前に~を必要に応じて、または、彼らはさまざまなワイルドカードとしてレンダリングされることを実現し、偽陽性を示し、さらにすべての検索にNOTがあるはずであることを認識しました。今は良いはずです。