我是vba的新手,我創建了一個用戶窗體並處理與「好」按鈕相關的代碼。我想檢查用戶窗體中的空字段,然後轉到另一個工作表,選擇頂部單元格(B3),然後填充下面空白單元格中的數據(B4),沿着行移動,直到列O.我希望它每次有人填寫用戶表單時都要做同樣的事情,並點擊「好」。Activecell.end.offset問題vba
然而,有一個錯誤消息突出線
工作表( 「Data_raw」)。選擇 範圍( 「B3」)。選擇
。我試圖用另一個文件,它是工作,我不知道爲什麼它會顯示爲這個文件:(錯誤。
誰能幫助我弄清楚什麼是錯我的代碼,請?.
這裏是我的代碼:
Private Sub CmdOKAY_Click()
'check all the fields to see if they are empty
If BoxRM = "" Then
MsgBox "Select a Relationship Manager"
End If
If TextCompany_name = "" Then
MsgBox " Enter a company name"
End If
If BoxCountry = "" Then
MsgBox "Select a country"
End If
If BoxTransactions = "" Then
MsgBox "Enter a volume for the transactions"
End If
If Btn_Yearly_Transactions.Value = False And Btn_Monthly_Transactions.Value = False Then
MsgBox "Select a frequency for the volume of transactions inputted"
End If
If BoxPosition_Vol = "" Then
MsgBox "Enter a volume for the positions"
End If
If Btn_Yearly_Positions.Value = False And Btn_Monthly_Positions.Value = False Then
MsgBox "Select a frequency for the volume of positions inputted"
End If
If CheckBox_RP.Value = False And CheckBox_TP.Value = False And CheckBox_TE.Value = False Then
MsgBox " Select at least one type of account"
End If
Worksheets("Data_raw").Range("b3").Select
ActiveCell.End(xlDown).Offset(1, 0).Select
ActiveCell.Value = RM
ActiveCell.Offset(0, 1).Select
ActiveCell.Value = NameCo
ActiveCell.Offset(0, 1).Select
ActiveCell.Value = Pays
ActiveCell.Offset(0, 1).Select
ActiveCell.Value = RepTrd
ActiveCell.Offset(0, 1).Select
ActiveCell.Value = FreqYrTrd
ActiveCell.Offset(0, 1).Select
ActiveCell.Value = OP
ActiveCell.Offset(0, 1).Select
ActiveCell.Value = FreqYrOP
ActiveCell.Offset(0, 1).Select
ActiveCell.Value = AvrgDays
ActiveCell.Offset(0, 1).Select
ActiveCell.Value = AcRP
ActiveCell.Offset(0, 1).Select
ActiveCell.Value = AcTP
ActiveCell.Offset(0, 1).Select
ActiveCell.Value = AcTE
ActiveCell.Offset(0, 1).Select
ActiveCell.Value = RP_Per
ActiveCell.Offset(0, 1).Select
ActiveCell.Value = TP_Per
ActiveCell.Offset(0, 1).Select
ActiveCell.Value = TE_Per
'copy the formats from the row above
Range("b4:o4").Copy
ActiveCell.Offset(0, -12).PasteSpecial xlPasteFormats
Application.CutCopyMode = False
Unload Me
End sub
您必須確保表格已被激活,然後才能在其上選擇範圍。不是你需要在這裏選擇它... – Rory