2017-06-06 80 views
0

我一直在努力完成這項工作。它在我的x64版本的辦公室中運行良好,但在同事的計算機上運行的不是x86。任何人都可以給我修補嗎?範圍類的自動填充方法失敗 - 我的代碼需要幫助

VBA引擎強調Range("AV5").AutoFill Destination:=Range("AV5:AV" & NoOfClients)的原因

Private Sub Check_Cases_Click() 
Dim NoOfClients As Long 

Application.DisplayAlerts = False 
CO_Select = Application.InputBox("Please input the name of caseworker you would like to check on.", "Caseworker Name") 
Range("A2").value = CO_Select 


Application.ScreenUpdating = False 
NoOfClients = Range("C2").value 
CO_Name = Range("A2").value 



CheckCaseMsg = MsgBox(CO_Name & ", there are " & NoOfClients & " clients under your name." & vbNewLine & vbNewLine & _ 
        "System will now calculate all your active cases and display " & vbNewLine & _ 
        "all the clients for your information." & vbNewLine & vbNewLine & _ 
        "Confirm?", vbYesNo, "Case Checking") 

If CheckCaseMsg = vbNo Then 
Exit Sub 
End If 


If CheckCaseMsg = vbYes Then 

'Remove the filters if one exists 
'========================================= 
If ActiveSheet.FilterMode Then 
Selection.AutoFilter 
End If 

Clear 
Startup_Formula 

Application.ScreenUpdating = False 
Application.Calculation = xlCalculationManual 

Range("AV5").AutoFill Destination:=Range("AV5:AV" & NoOfClients) 

Application.Calculation = xlCalculationAutomatic 

Range("GI_Table[[#All],[Client number]]").Copy 
Range("GI_Table[[#All],[Client number]]").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False 

Application.ScreenUpdating = True 

ActiveSheet.ListObjects("GI_Table").Range.AutoFilter Field:=2, Criteria1:= _ 
     Array("ACTIVE", "INACTIVE", "RENEWED"), Operator:=xlFilterValues 

GI_CustomSort 
GI_CustomSort 


MsgBox "Case Checking Ready", vbInformation, "Ready" 
End If 

Application.Calculation = xlCalculationAutomatic 
Application.ScreenUpdating = True 
Application.DisplayAlerts = True 
End Sub 
+0

它不必是Fill Down動作,我猜它可以是n次拷貝(n = NoOfClients)。我指定爲Startup_Formula的公式是一個子公式,它包含數組公式'Sub Startup_Formula() Sheets(「Grand Info Sheet」)。Range(「AV5」)。FormulaArray =「= IFERROR(INDEX(Table_MIS [CLIENTNUM],小(IF($ A $ 2 = Table_MIS [CASEWORKER],「&_ 」ROW(Table_MIS [CASEWORKER]) - MIN(ROW(Table_MIS [CASEWORKER]))+ 1,「」「」),ROW(AV5)) ),「」「」)「 End Sub' – herman925

+0

基本上我需要使用數組公式,並根據我在表中檢測到的NoOfClients填充它多次... – herman925

回答

0

好吧,我知道現在的問題,我想。

我在Sub for Worksheet_Activate中限制了滾動區域,並且NoOfClients的值超出了允許的數量!

所以我刪除了,我認爲現在沒事!這是我的最終代碼(現在滾動區域變得動態)

Private Sub Check_Cases_Click() 
Dim NoOfClients As Long 

ActiveSheet.ScrollArea = "" 
Application.Calculation = xlCalculationAutomatic 
Application.DisplayAlerts = False 
CO_Select = Application.InputBox("Please input the name of caseworker you would like to check on.", "Caseworker Name") 
Range("A2").value = CO_Select 


Application.ScreenUpdating = False 
NoOfClients = Range("C2").value 
CO_Name = Range("A2").value 



CheckCaseMsg = MsgBox(CO_Name & ", there are " & NoOfClients & " clients under your name." & vbNewLine & vbNewLine & _ 
        "System will now calculate all your active cases and display " & vbNewLine & _ 
        "all the clients for your information." & vbNewLine & vbNewLine & _ 
        "Confirm?", vbYesNo, "Case Checking") 

If CheckCaseMsg = vbNo Then 
Exit Sub 
End If 


If CheckCaseMsg = vbYes Then 

'Remove the filters if one exists 
'========================================= 
If ActiveSheet.FilterMode Then 
Selection.AutoFilter 
End If 

Clear 
Startup_Formula 


'Fill down the formula for n times where n= No of Clients of the Caseworker' 
'============================================================================= 
Dim Sht As Worksheet 

Application.ScreenUpdating = False 
Application.Calculation = xlCalculationManual 

Set Sht = Worksheets("Grand Info Sheet") 
NoOfClients = Range("C2").value 
NoOfClientsAdjusted = NoOfClients + 4 

Sht.Range("AV5").AutoFill Destination:=Sht.Range("AV5:AV" & NoOfClientsAdjusted) 

Application.Calculation = xlCalculationAutomatic 

Range("GI_Table[[#All],[Client number]]").Copy 
Range("GI_Table[[#All],[Client number]]").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False 

Application.ScreenUpdating = True 

GI_CustomSort 

MsgBox "Case Checking Ready", vbInformation, "Ready" 
Range("A1").Select 
End If 

ActiveSheet.ScrollArea = "A1:AW" & NoOfClientsAdjusted + 5 
Application.Calculation = xlCalculationAutomatic 
Application.ScreenUpdating = True 
Application.DisplayAlerts = True 
End Sub 
0

而不是僅僅Range("..").你應該嘗試

Dim sht as Worksheet 
Set sht = Worksheets("Name") 

sht.Range("..") 

等。

+0

你的意思是我應該'sht .Range(「AV5」)。AutoFill Destination:= Range(「AV5:AV」&NoOfClients)' – herman925

+0

'sht.Range(「AV5」)。AutoFill Destination:= sht.Range(「AV5:AV」&NoOfClients) '你錯過了一個,但是是試試 – UGP

+0

試過了,但它是相同的錯誤 – herman925

0

如果NoOfClients的值爲5,您將得到Autofill method of range class failed錯誤。結束行與起始行相同。這是一個簡單的重現錯誤的方法。

Sub Sample() 
    NoOfClients = 5 

    Range("AV5").AutoFill Destination:=Range("AV5:AV" & NoOfClients) 
End Sub 

.Autofill的替代方法是直接寫入範圍。對於前:

Range("AV5:AV" & NoOfClients).Formula = Range("AV5").Formula 
+0

感謝您的評論。但通常,我的NoOfClients就像200+。我沒有真正體驗過NoOfClients變爲5的任何測試場景。 – herman925

+0

基本上,我設置這個的原因是因爲我使用的數組公式是AV5(表的第一行)。我想多次填充(根據NoOfClients調用的數字(通常是100-200)) – herman925

+0

您是否嘗試過替代方法? –