我知道这个问题已被提出,但我想了解我做错了什么
我只想将一个单元格复制到另一个工作表中的另一个单元格。复制的单元格取决于按钮所在的行。
这是我的代码:
Option Explicit
Sub CreateButtons()
Dim i As Long
Dim shp As Object
Dim dblLeft As Double
Dim dblTop As Double
Dim dblWidth As Double
Dim dblHeight As Double
With Sheets("SALES UNFULFILLED")
dblLeft = .Columns("AZ:AZ").Left 'All buttons have same Left position
dblWidth = .Columns("AZ:AZ").Width 'All buttons have same Width
For i = 2 To 200 'Starts on row 2 and finishes row 20
dblHeight = .Rows(i).Height 'Set Height to height of row
dblTop = .Rows(i).Top 'Set Top top of row
Set shp = .Buttons.Add(dblLeft, dblTop, dblWidth, dblHeight)
shp.OnAction = "IdentifySelected"
shp.Characters.Text = "Invoice"
Next i
End With
End Sub
Sub IdentifySelected()
'NOTE: The button will always be on the active sheet
Dim strButtonName
Dim lngRow As Long
strButtonName = ActiveSheet.Shapes(Application.Caller).Name
lngRow = ActiveSheet.Shapes(strButtonName).TopLeftCell.Row
'MsgBox "Button is on row " & lngRow
Worksheets("invoice").Range(Cells(5, 3)).Value = Worksheets("SALES UNFULFILLED").Range(Cells(lngRow, 4)).Value
End Sub
我在这行代码上一直收到错误1004,但我不明白为什么
Worksheets("invoice").Range(Cells(5, 3)).Value = Worksheets("SALES UNFULFILLED").Range(Cells(lngRow, 4)).Value
我尝试通过“选择”更改“值”,但没有机会
答案 0 :(得分:1)
我认为你必须改变:
Worksheets("invoice").Range(Cells(5, 3)).Value = Worksheets("SALES UNFULFILLED").Range(Cells(lngRow, 4)).Value
到
Worksheets("invoice").Cells(5, 3).Value = Worksheets("SALES UNFULFILLED").Cells(lngRow, 4).Value
希望这个帮助