2016-11-08 26 views
-1

我是一名VBA新手,並試圖在Excel電子表格中「自動化」重複性任務。我試圖根據不同列中的大綱級別縮進列。我一直在嘗試改編來自類似任務的代碼,但卻遇到了困難。基本上我試圖完成的是讓宏讀取OutLvl列並根據大綱級別縮進下一列。下面是這個宏的屏幕截圖,並以黃色突出顯示它掛起的位置。任何意見或反饋意見,因爲我正在嘗試學習應用程序。謝謝! Indent Macro Attempt縮進excel中的列

+2

在你的問題中發佈你的代碼,而不是截圖:-) – Niclas

回答

0

它在這裏看起來像你沒有正確地初始化你打算迭代的範圍。 Range對象很棘手,因爲它實際上可以引用一組單元本身,這裏的數組用法是不必要的,甚至是令人困惑的。試試這樣的:

Dim OutLvl as Range ' This will refer to the whole range of interest 
Dim t as Range  ' Always good practice to declare all variables 
... ' Fill in the code as you have written 
Set OutLvl = Range("A1:A20") ' Now OutLvl refers to A1:A20 on the active sheet. 
    'Note that I can't possibly know how to appropriately set this range. 

For Each t in OutLvl 
    ... ' Now perform the loop as you have written 
Next t 

更多關於您收到的錯誤。注意我沒有看過這個,所以我不能說它的準確性: https://www.youtube.com/watch?v=kWT2YfSHpfM