各位程序員,您好!Excel中的公式轉化爲VBA代碼
我是新來的VBA,並應對現有的Excel模板做出很大的改變... 現在我的問題是,雖然試圖從excel中導出一個公式(它應該稍後點擊按鈕),我我無法使用這個簡單的步驟:
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
這並不工作,但插入我的傷心地大公式
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
當我得到一個語法錯誤,我甚至試圖逃避「」與\「\」但這隻適用於公式的一半。有人知道問題是什麼嗎?
真正的問題是爲什麼你需要這麼長的公式。無疑有更好的方法。也許從** codereview.stackexchange **這樣的問題開始** – CallumDA
@CallumDA很好,因爲我的老闆說,它似乎已經工作過,他們想繼續使用它 –
我能理解 - 羞辱你的老闆不是'儘管開放給更好的解決方案! – CallumDA