miro5
Дата: Суббота, 25.11.2017, 22:25 |
Сообщение № 1
Группа: Пользователи
Ранг: Новичок
Сообщений: 12
Репутация:
0
±
Замечаний:
0% ±
Excel 2007
Добрый вечер. Помогите, написал код переноса данных на лист, если делать отдельной кнопкой все хорошо, работает, но мне надо чтобы он работал в коде где выбрался лист на какой переносить. код ниже. подскажите что не так делаю. [vba]Код
Private Sub ComboBox1_Change() If Me.ComboBox1.Value = "Лист1" Then Sheets("Лист1").Activate ElseIf UserForm1.ComboBox1.Value = "Лист2" Then Sheets("Лист2").Activate Dim i As Long, strFileName As String ReDim arr(1 To Me.ListBox2.ListCount + 1, 1 To 6) For i = 0 To Me.ListBox2.ListCount - 1 arr(i + 1, 1) = Me.ListBox2.List(i, 1) arr(i + 1, 2) = Me.ListBox2.List(i, 2) arr(i + 1, 3) = Me.ListBox2.List(i, 3) arr(i + 1, 4) = Me.ListBox2.List(i, 4) arr(i + 1, 5) = Me.ListBox2.List(i, 5) arr(i + 1, 6) = Me.ListBox2.List(i, 6) Next arr(Me.ListBox2.ListCount + 1, 1) = " " arr(Me.ListBox2.ListCount + 1, 2) = " " arr(Me.ListBox2.ListCount + 1, 3) = "Итог:" arr(Me.ListBox2.ListCount + 1, 4) = sum arr(Me.ListBox2.ListCount + 1, 5) = " " arr(Me.ListBox2.ListCount + 1, 6) = " " ThisWorkbook.Worksheets("Лист2").Activate Range("A2").Resize(Me.ListBox2.ListCount + 1, 6).Value = arr Sheets(2).Select On Error Resume Next ElseIf UserForm1.ComboBox1.Value = "Лист3" Then Sheets("Лист3").Activate End If End Sub
[/vba]
Добрый вечер. Помогите, написал код переноса данных на лист, если делать отдельной кнопкой все хорошо, работает, но мне надо чтобы он работал в коде где выбрался лист на какой переносить. код ниже. подскажите что не так делаю. [vba]Код
Private Sub ComboBox1_Change() If Me.ComboBox1.Value = "Лист1" Then Sheets("Лист1").Activate ElseIf UserForm1.ComboBox1.Value = "Лист2" Then Sheets("Лист2").Activate Dim i As Long, strFileName As String ReDim arr(1 To Me.ListBox2.ListCount + 1, 1 To 6) For i = 0 To Me.ListBox2.ListCount - 1 arr(i + 1, 1) = Me.ListBox2.List(i, 1) arr(i + 1, 2) = Me.ListBox2.List(i, 2) arr(i + 1, 3) = Me.ListBox2.List(i, 3) arr(i + 1, 4) = Me.ListBox2.List(i, 4) arr(i + 1, 5) = Me.ListBox2.List(i, 5) arr(i + 1, 6) = Me.ListBox2.List(i, 6) Next arr(Me.ListBox2.ListCount + 1, 1) = " " arr(Me.ListBox2.ListCount + 1, 2) = " " arr(Me.ListBox2.ListCount + 1, 3) = "Итог:" arr(Me.ListBox2.ListCount + 1, 4) = sum arr(Me.ListBox2.ListCount + 1, 5) = " " arr(Me.ListBox2.ListCount + 1, 6) = " " ThisWorkbook.Worksheets("Лист2").Activate Range("A2").Resize(Me.ListBox2.ListCount + 1, 6).Value = arr Sheets(2).Select On Error Resume Next ElseIf UserForm1.ComboBox1.Value = "Лист3" Then Sheets("Лист3").Activate End If End Sub
[/vba] miro5
Ответить
Сообщение Добрый вечер. Помогите, написал код переноса данных на лист, если делать отдельной кнопкой все хорошо, работает, но мне надо чтобы он работал в коде где выбрался лист на какой переносить. код ниже. подскажите что не так делаю. [vba]Код
Private Sub ComboBox1_Change() If Me.ComboBox1.Value = "Лист1" Then Sheets("Лист1").Activate ElseIf UserForm1.ComboBox1.Value = "Лист2" Then Sheets("Лист2").Activate Dim i As Long, strFileName As String ReDim arr(1 To Me.ListBox2.ListCount + 1, 1 To 6) For i = 0 To Me.ListBox2.ListCount - 1 arr(i + 1, 1) = Me.ListBox2.List(i, 1) arr(i + 1, 2) = Me.ListBox2.List(i, 2) arr(i + 1, 3) = Me.ListBox2.List(i, 3) arr(i + 1, 4) = Me.ListBox2.List(i, 4) arr(i + 1, 5) = Me.ListBox2.List(i, 5) arr(i + 1, 6) = Me.ListBox2.List(i, 6) Next arr(Me.ListBox2.ListCount + 1, 1) = " " arr(Me.ListBox2.ListCount + 1, 2) = " " arr(Me.ListBox2.ListCount + 1, 3) = "Итог:" arr(Me.ListBox2.ListCount + 1, 4) = sum arr(Me.ListBox2.ListCount + 1, 5) = " " arr(Me.ListBox2.ListCount + 1, 6) = " " ThisWorkbook.Worksheets("Лист2").Activate Range("A2").Resize(Me.ListBox2.ListCount + 1, 6).Value = arr Sheets(2).Select On Error Resume Next ElseIf UserForm1.ComboBox1.Value = "Лист3" Then Sheets("Лист3").Activate End If End Sub
[/vba] Автор - miro5 Дата добавления - 25.11.2017 в 22:25
Manyasha
Дата: Воскресенье, 26.11.2017, 00:59 |
Сообщение № 2
Группа: Модераторы
Ранг: Старожил
Сообщений: 2198
Репутация:
898
±
Замечаний:
0% ±
Excel 2010, 2016
miro5 , здравствуйте. Попробуйте так: [vba]Код
Private Sub ComboBox1_Change() Dim i As Long, strFileName As String ReDim arr(1 To Me.ListBox2.ListCount + 1, 1 To 6) For i = 0 To Me.ListBox2.ListCount - 1 arr(i + 1, 1) = Me.ListBox2.List(i, 1) arr(i + 1, 2) = Me.ListBox2.List(i, 2) arr(i + 1, 3) = Me.ListBox2.List(i, 3) arr(i + 1, 4) = Me.ListBox2.List(i, 4) arr(i + 1, 5) = Me.ListBox2.List(i, 5) arr(i + 1, 6) = Me.ListBox2.List(i, 6) Next arr(Me.ListBox2.ListCount + 1, 1) = " " arr(Me.ListBox2.ListCount + 1, 2) = " " arr(Me.ListBox2.ListCount + 1, 3) = "Итог:" arr(Me.ListBox2.ListCount + 1, 4) = Sum arr(Me.ListBox2.ListCount + 1, 5) = " " arr(Me.ListBox2.ListCount + 1, 6) = " " ThisWorkbook.Worksheets(UserForm1.ComboBox1.Value).Range("A2").Resize(Me.ListBox2.ListCount + 1, 6).Value = arr End Sub
[/vba] Если не то, показывайте пример в файле.
miro5 , здравствуйте. Попробуйте так: [vba]Код
Private Sub ComboBox1_Change() Dim i As Long, strFileName As String ReDim arr(1 To Me.ListBox2.ListCount + 1, 1 To 6) For i = 0 To Me.ListBox2.ListCount - 1 arr(i + 1, 1) = Me.ListBox2.List(i, 1) arr(i + 1, 2) = Me.ListBox2.List(i, 2) arr(i + 1, 3) = Me.ListBox2.List(i, 3) arr(i + 1, 4) = Me.ListBox2.List(i, 4) arr(i + 1, 5) = Me.ListBox2.List(i, 5) arr(i + 1, 6) = Me.ListBox2.List(i, 6) Next arr(Me.ListBox2.ListCount + 1, 1) = " " arr(Me.ListBox2.ListCount + 1, 2) = " " arr(Me.ListBox2.ListCount + 1, 3) = "Итог:" arr(Me.ListBox2.ListCount + 1, 4) = Sum arr(Me.ListBox2.ListCount + 1, 5) = " " arr(Me.ListBox2.ListCount + 1, 6) = " " ThisWorkbook.Worksheets(UserForm1.ComboBox1.Value).Range("A2").Resize(Me.ListBox2.ListCount + 1, 6).Value = arr End Sub
[/vba] Если не то, показывайте пример в файле.Manyasha
ЯД: 410013299366744 WM: R193491431804
Ответить
Сообщение miro5 , здравствуйте. Попробуйте так: [vba]Код
Private Sub ComboBox1_Change() Dim i As Long, strFileName As String ReDim arr(1 To Me.ListBox2.ListCount + 1, 1 To 6) For i = 0 To Me.ListBox2.ListCount - 1 arr(i + 1, 1) = Me.ListBox2.List(i, 1) arr(i + 1, 2) = Me.ListBox2.List(i, 2) arr(i + 1, 3) = Me.ListBox2.List(i, 3) arr(i + 1, 4) = Me.ListBox2.List(i, 4) arr(i + 1, 5) = Me.ListBox2.List(i, 5) arr(i + 1, 6) = Me.ListBox2.List(i, 6) Next arr(Me.ListBox2.ListCount + 1, 1) = " " arr(Me.ListBox2.ListCount + 1, 2) = " " arr(Me.ListBox2.ListCount + 1, 3) = "Итог:" arr(Me.ListBox2.ListCount + 1, 4) = Sum arr(Me.ListBox2.ListCount + 1, 5) = " " arr(Me.ListBox2.ListCount + 1, 6) = " " ThisWorkbook.Worksheets(UserForm1.ComboBox1.Value).Range("A2").Resize(Me.ListBox2.ListCount + 1, 6).Value = arr End Sub
[/vba] Если не то, показывайте пример в файле.Автор - Manyasha Дата добавления - 26.11.2017 в 00:59
miro5
Дата: Воскресенье, 26.11.2017, 12:36 |
Сообщение № 3
Группа: Пользователи
Ранг: Новичок
Сообщений: 12
Репутация:
0
±
Замечаний:
0% ±
Excel 2007
Добавляю файл
Сообщение отредактировал miro5 - Воскресенье, 26.11.2017, 23:19
Ответить
Сообщение Добавляю файл Автор - miro5 Дата добавления - 26.11.2017 в 12:36
miro5
Дата: Воскресенье, 26.11.2017, 23:20 |
Сообщение № 4
Группа: Пользователи
Ранг: Новичок
Сообщений: 12
Репутация:
0
±
Замечаний:
0% ±
Excel 2007
Тему можно закрыть, сам додумался
Тему можно закрыть, сам додумался miro5
Ответить
Сообщение Тему можно закрыть, сам додумался Автор - miro5 Дата добавления - 26.11.2017 в 23:20
Pelena
Дата: Воскресенье, 26.11.2017, 23:22 |
Сообщение № 5
Группа: Админы
Ранг: Местный житель
Сообщений: 19182
Репутация:
4420
±
Замечаний:
±
Excel 365 & Mac Excel
А поделиться решением не хотите?
А поделиться решением не хотите? Pelena
"Черт возьми, Холмс! Но как??!!" Ю-money 41001765434816
Ответить
Сообщение А поделиться решением не хотите? Автор - Pelena Дата добавления - 26.11.2017 в 23:22