У меня два (2) листа. У первого есть кнопка. Второй лист - это моя сводная страница, и я планирую разместить здесь кнопку, которая будет связана с кнопкой на моем первом листе. Однако я получаю
Ошибка времени выполнения '1004': Ошибка выбора метода класса Range.
Я назначил Command1_Click () моей кнопкой на Sheet2
Модуль1:
Sub Command1_Click()
Call Model01
End Sub
Модуль2:
Sub Model01()
Sheet1.Range("C8:GF8").Value = Sheet1.Range("C240:GF240").Value
Sheet1.Range("B7").Value = Sheet1.Range("B240").Value
r = DataUpdate()
End Sub
Модуль3:
Function DataUpdate()
If (validateVer() = False) Then
Exit Function
End If
Dim AsCn, AsRs, SQL
Dim x, y, WDATE, NGQTY, FAQTY, RWQTY, RNQTY, TotalCell, TotalCellx
Dim FA_TBL As Variant ' (y, x)
Dim RW_TBL As Variant ' (y, x)
Dim RN_TBL As Variant ' (y, x)
Dim NG_TBL As Variant ' (y, x)
'Sheet => Table
Sheet1.Range("C2:GS2").Select
Selection.ClearContents
FA_TBL = Sheet1.Range("A2:GS2")
Sheet1.Range("C4:GS4").Select
Selection.ClearContents
RW_TBL = Sheet1.Range("A4:GS4")
Sheet1.Range("C5:GS5").Select
Selection.ClearContents
RN_TBL = Sheet1.Range("A5:GS5")
Sheet1.Range("A9:GS208").Select
Selection.ClearContents
Sheet1.Range("C9").Select
NG_TBL = Sheet1.Range("A8:GS208")
'Connect DataBase ODBC
Set AsCn = CreateObject("ADODB.Connection")
AsCn.Open "Provider=IBMDA400;Data Source=FCP2040;", "FCPMIS", "AUTOSENT"
'AsCn.Open "dsn=FCP2040;uid=FCPMIS;pwd=AUTOSENT"
'Get Total cell
TotalCell = 3
While NG_TBL(1, TotalCell) <> "Total"
TotalCell = TotalCell + 1
Wend
..
'Get NG Qty
y = 2
NGQTY = 0
While Not (AsRs.EOF)
NG_TBL(y, 1) = AsRs(1)
NG_TBL(y, 2) = AsRs(2)
NGQTY = 0
x = 3
While x < TotalCell
WDATE = Right(Year(NG_TBL(1, x)), 2) & Right("00" & Month(NG_TBL(1, x)), 2) & Right("00" & Day(NG_TBL(1, x)), 2)
If Not (AsRs.EOF) Then
If ((NG_TBL(y, 1) = AsRs(1)) And _
((WDATE = AsRs(0)) Or ((x + 1) = TotalCell))) Then
NG_TBL(y, x) = AsRs(3)
NGQTY = NGQTY + AsRs(3)
AsRs.MoveNext
Else
If FA_TBL(1, x) <> "" Then
NG_TBL(y, x) = 0
End If
End If
Else
If FA_TBL(1, x) <> "" Then
NG_TBL(y, x) = 0
End If
End If
x = x + 1
Wend
NG_TBL(y, TotalCell) = NGQTY
y = y + 1
Wend
'Sheet => Table
Sheet1.Range("A2:GS2") = FA_TBL
Sheet1.Range("A4:GS4") = RW_TBL
Sheet1.Range("A5:GS5") = RN_TBL
Sheet1.Range("A8:GS208") = NG_TBL
'--------------------------------------------------------------------------------
' Sort
'--------------------------------------------------------------------------------
If (TotalCell \ 26) = 0 Then
TotalCellx = Chr(TotalCell + 64)
Else
TotalCellx = Chr(TotalCell \ 26 + 64) & Chr(TotalCell Mod 26 + 64)
End If
Sheet1.Range("A8:" & TotalCellx & "100").Select
Selection.Sort Key1:=Range(TotalCellx & "9"), Order1:=xlDescending, Header:=xlGuess _
, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
SortMethod:=xlPinYin
Sheet1.Range("C9").Select
'Close Recordset
AsRs.Close
Set AsRs = Nothing
'Close DataBase ODBC
AsCn.Close
Set AsCn = Nothing
End Function