У меня есть раскрывающийся список в ячейках G3:G102
, где вы можете выбрать значение от 1 до 50. При выборе числа из списка следующие три столбца заполняются VBA такими вещами, как:
1.
2.
3.
и
On floor 1: ?
On floor 2: ?
On floor 3: ?
Итак, у меня есть этот код VBA.
Private Sub Worksheet_Change(ByVal Target As Range)
Dim KeyCells As Range
Set KeyCells = Range("G3:G102")
If Not Application.Intersect(KeyCells, Range(Target.Address)) _
Is Nothing Then
' If any one of these cells in the range KeyCells has been modified, then retrieve its value
floorValue = Range(Target.Address)
' Here is the loop I use it will loop X-amount of times based on the number from 'KeyCells'
Dim i As Integer
For i = 1 To Range(Target.Address).Value
' myText and myText2 are two variables that I am populating here with multiple lines.
myText = myText & i & "." & vbNewLine
myText2 = myText2 & "On floor " & i & ": ?" & vbNewLine
Next i
'Then insert that data into the cells to the right
Target.Offset(0, 1).Value = myText
Target.Offset(0, 2).Value = myText2
Target.Offset(0, 3).Value = myText2
End If
End Sub
У меня проблема
Если явставка в несколько ячеек одновременно или перетаскивание данных в несколько ячеек одновременно, я получу ошибку Type mismatch
, особенно в этой точке: For i = 1 To Range(Target.Address).Value