[这里是尝试包含单元格引用时的错误代码] [1]
Private Sub adduserCommandButton_Click()
Dim finduserrow As Range
Dim rowNo As Integer
Dim findsalesrow As Range
Dim salesNo As Integer
Dim icounter As Long
Dim sales As String
Dim sumformula As String
Dim username As String
Dim lastrow As Long
Dim userMsheet As Worksheet
Dim currentSheetname As Worksheet
Set userMsheet = Sheets("User&Sales Maintenance")
sales = "No. of Sales"
'Value to search for user row
Set findsalesrow = ActiveSheet.Range("C:C").Find(What:=sales)
username = usernameComboBox.Text
If findsalesrow Is Nothing Then
MsgBox "User not found! Please add user!"
Else
salesNo = findsalesrow.Row
sumformula = "=Sum(H" & salesNo - 1 & " : H" & salesNo & ")"
ActiveSheet.Rows(salesNo - 1).Insert Shift:=xlShiftDown,
CopyOrigin:=xlFormatFromRightOrBelow
ActiveSheet.Rows(salesNo - 1).Insert Shift:=xlShiftDown,
CopyOrigin:=xlFormatFromRightOrBelow
ActiveSheet.Cells(salesNo - 1, 2).Value = countryTextBox.Value
ActiveSheet.Cells(salesNo - 1, 3).Value = usernameComboBox.Value
ActiveSheet.Cells(salesNo - 1, 5).Value = ActiveSheet.Name & "IPC Dual
Routers & Leased Lines"
ActiveSheet.Cells(salesNo - 1, 8).Formula = "=$H$5"
ActiveSheet.Cells(salesNo, 4).Value = companyComboBox.Value
ActiveSheet.Cells(salesNo, 5).Value = ActiveSheet.Name & "Client
connection -" & companyComboBox.Value
ActiveSheet.Cells(salesNo, 6).Value = oneTimeTextBox.Value
ActiveSheet.Cells(salesNo, 7).Value = actualMonthlyTextBox.Value
ActiveSheet.Cells(salesNo, 8).Value = actualMonthlyTextBox.Value
ActiveSheet.Cells(salesNo, 9).Value = "Monthly Cost Charge Gross on " &
usernameComboBox.Value
ActiveSheet.Rows(salesNo + 1).Insert Shift:=xlShiftDown,
CopyOrigin:=xlFormatFromRightOrBelow
ActiveSheet.Range(Cells(salesNo + 1, 2), Cells(salesNo + 1, 10)).Select
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 8388736
.TintAndShade = 0
.PatternTintAndShade = 0
End With
ActiveSheet.Cells(salesNo + 1, 5).Value = "Subtotal for " &
usernameComboBox.Value
ActiveSheet.Cells(salesNo + 1, 5).Select
With Selection.Font
.ThemeColor = xlThemeColorDark1
.TintAndShade = 0
.Bold = True
End With
ActiveSheet.Cells(salesNo + 1, 8).Value = sumformula
ActiveSheet.Cells(salesNo + 1, 8).Select
With Selection.Font
.ThemeColor = xlThemeColorDark1
.TintAndShade = 0
.Bold = True
End With
MsgBox username & " 's Details Has Been added!"
countryTextBox.Text = ""
companyComboBox.Text = ""
usernameComboBox.Text = ""
oneTimeTextBox.Text = ""
actualMonthlyTextBox.Text = ""
With userMsheet
lastrow = Sheets("User&Sales Maintenance").Range("A" &
Rows.Count).End(xlUp).Row
Sheets("User&Sales Maintenance").Cells(lastrow + 1, "A").Formula =
"=HYPERLINK(" & ActiveSheet.Name & "!" & Cells(salesNo - 1, 3).Address
& "," & usernameComboBox.Value & ")"
End With
End If
End Sub
活动表的名称也称为共享公司,因此其目的是将工作表(“用户和销售维护”)中的单元格与各个单元格链接到名为“共享公司”的工作表中
有人可以向我解释如何解决此问题吗?我似乎无法弄清楚在脚本中使用activesheet.name以及单元格(salesno-1,3)时在何处以及何处加上&和引号。预先感谢!