我今天學習vba,我是一個新手,我有幾個關於代碼的問題以及它的寫法。我已經下載了一個例子,我試圖理解它。我知道C的一些概念。我也想說我不是母語的,我很抱歉在英語中有任何錯誤。VBA疑惑初學者
下面的代碼:
Set rg = Worksheets("TabPaciente").Range("Paciente")
i = 0
glQtdPaciente = 0
Do While rg.Cells(i + 3, 1) <> ""
i = i + 1
Loop
glQtdPaciente = i
ReDim mPaciente(glQtdPaciente)
p = Worksheets("TabFila").Range("p")
InstCheg = 0
For i = 1 To glQtdPaciente
mPaciente(i).CodPaciente = rg.Cells(i + 2, 1)
If Rnd < p Then
mPaciente(i).PriorPaciente = 1
Else
mPaciente(i).PriorPaciente = 2
End If
mPaciente(i).IntvChegDistr = rg.Cells(i + 2, 2)
mPaciente(i).Par1 = rg.Cells(i + 2, 3)
mPaciente(i).Par2 = rg.Cells(i + 2, 4)
mPaciente(i).Par3 = rg.Cells(i + 2, 5)
mPaciente(i).Par4 = rg.Cells(i + 2, 6)
現在我得到了一些問題,我會很高興,如果有人能幫助我。
當我寫
Set rg = Worksheets("TabPaciente").Range("Paciente")
1)形式現在每次它是寫rg.somethingelsehere它會選擇工作表「TabPaciente」和範圍「Paciente」?它類似於C中#define的概念嗎?
Do While rg.Cells(i + 3, 1) <> ""
2日)由於RG被「定義」像上面這行我能理解像這個問題:「去到工作表TabPaciente和選擇範圍Paciente,並選擇單元格(行,列)?這個怎麼樣<> ""
,我不明白這一點的想法。
If Rnd < p Then
mPaciente(i).PriorPaciente = 1
Else
mPaciente(i).PriorPaciente = 2
End If
3日)這是什麼mPaciente(i)和PriorPaciente意味着什麼嗎?我的意思是他們的概念,是像工作表和範圍,我不這麼認爲,因爲我沒有工作表名爲mPaciente。
在此先感謝您的幫助。
如果您只針對每個問題提出一個問題,則更有可能得到答案。 – BenV 2010-11-21 05:06:40