我有下面的代碼讓數據填充到我的工作表(「測試」)中。 r是表示在該工作表中將添加多少組數據/行數的數字。但是,當我打電話給該模塊時,我從第二次參考「r」。它自己加起來。 如何從同一行/行中獲取數據輸入到工作表上的同一行?固定值一直保持加起來
Sub addVal(Ctrl As String, Col As Single, tRow As Single)
Dim ii As Single
ii = Me.packageNum.Value - 1 'my control name start from 0 to 9(max)
For i = 0 To ii
Worksheets("test").Cells(tRow, Col).Value = Application.WorksheetFunction.Trim(StrConv(Me.controls(Ctrl & i).Text, vbProperCase))
tRow = tRow+ 1
Next
End Sub
Private Sub Confirm_Click()
Dim r As Single
Call addVal("lot", 4, fEmpty("test")) 'the fEmpty is another module to get the first empty row. working fine
r = 2 ' that was a variable number that get from another userform. now I just change to 2 for testing
Call addVal("estate", 8, r) 'r = 2
Call addVal("stage", 9, r) 'r = 4 (+2)
Call addVal("address", 5, r) 'r = 6 (+2 again)
Call addVal("suburb", 6, r) ' and so on
....... ' calling more same module
End Sub
你只在'Confirm_Click()'中使用'r'?從上面的代碼中,我看不到任何'r'變成了'r = 2'的地方。所以你必須在代碼的另一部分添加它,然後再回到下一次調用'addVal()' – DragonSamu