Всем привет! Не могу никак написать макрос по заполнению таблицы....
Как это должно работать: Есть файл В нем 2 листа. 1й лист - таблица 2й лист - поле для макроса В таблице 42 колонки, 1я - номер ID, 35 - накладная, 36 - чек, 37 - дата, 38 - поставщик, 39 - возврат, 40 - брак Надо сделать так, чтобы внося на втором листе в определенные ячейки данные, они должны переноситься по нажатию кнопки «добавить» в лист 1, в те строки и в те столбцы, к которым принадлежит ID. Но на листе 1 - этот ID может быть указан несколько раз. Надо внести эту инфу во все места (ячейки), где указан этот ID. Это было бы удобнее через созданную пользовательскую форму, чтобы листы дополнительные не плодить.
Умоляю помогите
Всем привет! Не могу никак написать макрос по заполнению таблицы....
Как это должно работать: Есть файл В нем 2 листа. 1й лист - таблица 2й лист - поле для макроса В таблице 42 колонки, 1я - номер ID, 35 - накладная, 36 - чек, 37 - дата, 38 - поставщик, 39 - возврат, 40 - брак Надо сделать так, чтобы внося на втором листе в определенные ячейки данные, они должны переноситься по нажатию кнопки «добавить» в лист 1, в те строки и в те столбцы, к которым принадлежит ID. Но на листе 1 - этот ID может быть указан несколько раз. Надо внести эту инфу во все места (ячейки), где указан этот ID. Это было бы удобнее через созданную пользовательскую форму, чтобы листы дополнительные не плодить.
Суть в том, чтобы при нажатии на кнопку "добавить" на втором листе - инфа скопировалась в базу и со второго листа поле очистилось. Может будет проще через пользовательскую форму, но мне уже хоть как надо. В этом файле попытался отразить хоть как-то действительность в 100.000 позиций.....
Грубо говоря - нужна форма как родная в EXCEL - только с возможностью поиска по таблице
Суть в том, чтобы при нажатии на кнопку "добавить" на втором листе - инфа скопировалась в базу и со второго листа поле очистилось. Может будет проще через пользовательскую форму, но мне уже хоть как надо. В этом файле попытался отразить хоть как-то действительность в 100.000 позиций.....
Грубо говоря - нужна форма как родная в EXCEL - только с возможностью поиска по таблицеmenyazdeznet
чтобы при нажатии на кнопку "добавить" на втором листе - инфа скопировалась в базу и со второго листа поле очистилось.
[vba]
Код
Sub iVvod() Dim i As Long Dim FoundCell As Range Dim FAdr As String With Worksheets("БАЗА") Set FoundCell = .Columns(1).Find(Range("A3"), , xlValues, xlWhole) If Not FoundCell Is Nothing Then FAdr = FoundCell.Address Do .Cells(FoundCell.Row, "AI") = Range("D3") '№ чека .Cells(FoundCell.Row, "AJ") = Range("J3") 'дата чека .Cells(FoundCell.Row, "AK") = Range("M3") 'поставщик 'и т.п. Set FoundCell = .Columns(1).FindNext(FoundCell) Loop While FoundCell.Address <> FAdr End If End With For i = 1 To 22 Step 3 Range(Cells(3, i), Cells(4, i + 2)).ClearContents Next End Sub
[/vba]
Цитата
чтобы при нажатии на кнопку "добавить" на втором листе - инфа скопировалась в базу и со второго листа поле очистилось.
[vba]
Код
Sub iVvod() Dim i As Long Dim FoundCell As Range Dim FAdr As String With Worksheets("БАЗА") Set FoundCell = .Columns(1).Find(Range("A3"), , xlValues, xlWhole) If Not FoundCell Is Nothing Then FAdr = FoundCell.Address Do .Cells(FoundCell.Row, "AI") = Range("D3") '№ чека .Cells(FoundCell.Row, "AJ") = Range("J3") 'дата чека .Cells(FoundCell.Row, "AK") = Range("M3") 'поставщик 'и т.п. Set FoundCell = .Columns(1).FindNext(FoundCell) Loop While FoundCell.Address <> FAdr End If End With For i = 1 To 22 Step 3 Range(Cells(3, i), Cells(4, i + 2)).ClearContents Next End Sub
Kuzmich, ОГРОМНОЕ СПАСИБО!!! А как сделать так, чтобы при заполнении не всех полей на листе "Форма для заполнения", прежние данные не очищались на листе "База"? А то получается так, что если я "довношу" данные, то другие ячейки в строке - очищаются
Kuzmich, ОГРОМНОЕ СПАСИБО!!! А как сделать так, чтобы при заполнении не всех полей на листе "Форма для заполнения", прежние данные не очищались на листе "База"? А то получается так, что если я "довношу" данные, то другие ячейки в строке - очищаютсяmenyazdeznet
Сообщение отредактировал menyazdeznet - Понедельник, 02.07.2018, 08:51
А как сделать так, чтобы при заполнении не всех полей на листе "Форма для заполнения"
Тогда сообщение о незаполненном поле и выход из программы [vba]
Код
Sub iVvod() Dim i As Long Dim FoundCell As Range Dim FAdr As String With Worksheets("БАЗА") Set FoundCell = .Columns(1).Find(Range("A3"), , xlValues, xlWhole) If Not FoundCell Is Nothing Then FAdr = FoundCell.Address For i = 4 To 22 Step 3 If Cells(3, i) = "" Then MsgBox "Не заполнено поле: " & Cells(1, i): Exit Sub Next Do .Cells(FoundCell.Row, "AI") = Range("D3") '№ чека .Cells(FoundCell.Row, "AJ") = Range("J3") 'дата чека .Cells(FoundCell.Row, "AK") = Range("M3") 'поставщик 'и т.п. Set FoundCell = .Columns(1).FindNext(FoundCell) Loop While FoundCell.Address <> FAdr Else MsgBox "На листе 'БАЗА' нет номера: " & Range("A3"): Exit Sub End If End With For i = 1 To 22 Step 3 Range(Cells(3, i), Cells(4, i + 2)).ClearContents Next End Sub
[/vba]
Цитата
А как сделать так, чтобы при заполнении не всех полей на листе "Форма для заполнения"
Тогда сообщение о незаполненном поле и выход из программы [vba]
Код
Sub iVvod() Dim i As Long Dim FoundCell As Range Dim FAdr As String With Worksheets("БАЗА") Set FoundCell = .Columns(1).Find(Range("A3"), , xlValues, xlWhole) If Not FoundCell Is Nothing Then FAdr = FoundCell.Address For i = 4 To 22 Step 3 If Cells(3, i) = "" Then MsgBox "Не заполнено поле: " & Cells(1, i): Exit Sub Next Do .Cells(FoundCell.Row, "AI") = Range("D3") '№ чека .Cells(FoundCell.Row, "AJ") = Range("J3") 'дата чека .Cells(FoundCell.Row, "AK") = Range("M3") 'поставщик 'и т.п. Set FoundCell = .Columns(1).FindNext(FoundCell) Loop While FoundCell.Address <> FAdr Else MsgBox "На листе 'БАЗА' нет номера: " & Range("A3"): Exit Sub End If End With For i = 1 To 22 Step 3 Range(Cells(3, i), Cells(4, i + 2)).ClearContents Next End Sub
Sub iVvod() Dim i As Long Dim FoundCell As Range Dim FAdr As String With Worksheets("ÁÀÇÀ") Set FoundCell = .Columns(1).Find(Range("A3"), , xlValues, xlWhole) If Not FoundCell Is Nothing Then FAdr = FoundCell.Address Do If .Cells(FoundCell.Row, "AH") <> 0 Then .Cells(FoundCell.Row, "AH") = .Cells(FoundCell.Row, "AH") Else .Cells(FoundCell.Row, "AH") = Range("D3") If .Cells(FoundCell.Row, "AI") <> 0 Then .Cells(FoundCell.Row, "AH") = .Cells(FoundCell.Row, "AH") Else .Cells(FoundCell.Row, "AI") = Range("G3") If .Cells(FoundCell.Row, "AJ") <> 0 Then .Cells(FoundCell.Row, "AH") = .Cells(FoundCell.Row, "AH") Else .Cells(FoundCell.Row, "AJ") = Range("J3") If .Cells(FoundCell.Row, "AK") <> 0 Then .Cells(FoundCell.Row, "AH") = .Cells(FoundCell.Row, "AH") Else .Cells(FoundCell.Row, "AK") = Range("M3") If .Cells(FoundCell.Row, "AL") <> 0 Then .Cells(FoundCell.Row, "AH") = .Cells(FoundCell.Row, "AH") Else .Cells(FoundCell.Row, "AL") = Range("P3") If .Cells(FoundCell.Row, "AM") <> 0 Then .Cells(FoundCell.Row, "AH") = .Cells(FoundCell.Row, "AH") Else .Cells(FoundCell.Row, "AM") = Range("S3") If .Cells(FoundCell.Row, "AN") <> 0 Then .Cells(FoundCell.Row, "AH") = .Cells(FoundCell.Row, "AH") Else .Cells(FoundCell.Row, "AM") = Range("S3") If .Cells(FoundCell.Row, "AO") <> 0 Then .Cells(FoundCell.Row, "AH") = .Cells(FoundCell.Row, "AH") Else .Cells(FoundCell.Row, "AO") = Range("Y3") Set FoundCell = .Columns(1).FindNext(FoundCell) Loop While FoundCell.Address <> FAdr End If End With For i = 1 To 22 Step 3 Range(Cells(3, i), Cells(4, i + 2)).ClearContents Next End Sub
[/vba] А вот тут не могу понять в чем ошибка?
Kuzmich, [vba]
Код
Sub iVvod() Dim i As Long Dim FoundCell As Range Dim FAdr As String With Worksheets("ÁÀÇÀ") Set FoundCell = .Columns(1).Find(Range("A3"), , xlValues, xlWhole) If Not FoundCell Is Nothing Then FAdr = FoundCell.Address Do If .Cells(FoundCell.Row, "AH") <> 0 Then .Cells(FoundCell.Row, "AH") = .Cells(FoundCell.Row, "AH") Else .Cells(FoundCell.Row, "AH") = Range("D3") If .Cells(FoundCell.Row, "AI") <> 0 Then .Cells(FoundCell.Row, "AH") = .Cells(FoundCell.Row, "AH") Else .Cells(FoundCell.Row, "AI") = Range("G3") If .Cells(FoundCell.Row, "AJ") <> 0 Then .Cells(FoundCell.Row, "AH") = .Cells(FoundCell.Row, "AH") Else .Cells(FoundCell.Row, "AJ") = Range("J3") If .Cells(FoundCell.Row, "AK") <> 0 Then .Cells(FoundCell.Row, "AH") = .Cells(FoundCell.Row, "AH") Else .Cells(FoundCell.Row, "AK") = Range("M3") If .Cells(FoundCell.Row, "AL") <> 0 Then .Cells(FoundCell.Row, "AH") = .Cells(FoundCell.Row, "AH") Else .Cells(FoundCell.Row, "AL") = Range("P3") If .Cells(FoundCell.Row, "AM") <> 0 Then .Cells(FoundCell.Row, "AH") = .Cells(FoundCell.Row, "AH") Else .Cells(FoundCell.Row, "AM") = Range("S3") If .Cells(FoundCell.Row, "AN") <> 0 Then .Cells(FoundCell.Row, "AH") = .Cells(FoundCell.Row, "AH") Else .Cells(FoundCell.Row, "AM") = Range("S3") If .Cells(FoundCell.Row, "AO") <> 0 Then .Cells(FoundCell.Row, "AH") = .Cells(FoundCell.Row, "AH") Else .Cells(FoundCell.Row, "AO") = Range("Y3") Set FoundCell = .Columns(1).FindNext(FoundCell) Loop While FoundCell.Address <> FAdr End If End With For i = 1 To 22 Step 3 Range(Cells(3, i), Cells(4, i + 2)).ClearContents Next End Sub
[/vba] А вот тут не могу понять в чем ошибка?menyazdeznet
Сообщение отредактировал menyazdeznet - Понедельник, 02.07.2018, 10:52
Sub iVvod() Dim i As Long Dim FoundCell As Range Dim FAdr As String With Worksheets("БАЗА") Set FoundCell = .Columns(1).Find(Range("A3"), , xlValues, xlWhole) If Not FoundCell Is Nothing Then FAdr = FoundCell.Address Do If IsEmpty(FoundCell.Row, "AH") = False Then .Cells(FoundCell.Row, "AH") = .Cells(FoundCell.Row, "AH") Else .Cells(FoundCell.Row, "AH") = Range("D3") If IsEmpty(FoundCell.Row, "AI") = False Then .Cells(FoundCell.Row, "AI") = .Cells(FoundCell.Row, "AI") Else .Cells(FoundCell.Row, "AI") = Range("G3") If IsEmpty(FoundCell.Row, "AJ") = False Then .Cells(FoundCell.Row, "AJ") = .Cells(FoundCell.Row, "AJ") Else .Cells(FoundCell.Row, "AJ") = Range("J3") If IsEmpty(FoundCell.Row, "AK") = False Then .Cells(FoundCell.Row, "AK") = .Cells(FoundCell.Row, "AK") Else .Cells(FoundCell.Row, "AK") = Range("M3") If IsEmpty(FoundCell.Row, "AL") = False Then .Cells(FoundCell.Row, "AL") = .Cells(FoundCell.Row, "AL") Else .Cells(FoundCell.Row, "AL") = Range("P3") If IsEmpty(FoundCell.Row, "AM") = False Then .Cells(FoundCell.Row, "AM") = .Cells(FoundCell.Row, "AM") Else .Cells(FoundCell.Row, "AM") = Range("S3") If IsEmpty(FoundCell.Row, "AN") = False Then .Cells(FoundCell.Row, "AN") = .Cells(FoundCell.Row, "AN") Else .Cells(FoundCell.Row, "AN") = Range("V3") If IsEmpty(FoundCell.Row, "AO") = False Then .Cells(FoundCell.Row, "AO") = .Cells(FoundCell.Row, "AO") Else .Cells(FoundCell.Row, "AO") = Range("Y3") End If Set FoundCell = .Columns(1).FindNext(FoundCell) Loop While FoundCell.Address <> FAdr End If End With For i = 1 To 22 Step 3 Range(Cells(3, i), Cells(4, i + 2)).ClearContents Next End Sub
Sub iVvod() Dim i As Long Dim FoundCell As Range Dim FAdr As String With Worksheets("БАЗА") Set FoundCell = .Columns(1).Find(Range("A3"), , xlValues, xlWhole) If Not FoundCell Is Nothing Then FAdr = FoundCell.Address Do If IsEmpty(FoundCell.Row, "AH") = False Then .Cells(FoundCell.Row, "AH") = .Cells(FoundCell.Row, "AH") Else .Cells(FoundCell.Row, "AH") = Range("D3") If IsEmpty(FoundCell.Row, "AI") = False Then .Cells(FoundCell.Row, "AI") = .Cells(FoundCell.Row, "AI") Else .Cells(FoundCell.Row, "AI") = Range("G3") If IsEmpty(FoundCell.Row, "AJ") = False Then .Cells(FoundCell.Row, "AJ") = .Cells(FoundCell.Row, "AJ") Else .Cells(FoundCell.Row, "AJ") = Range("J3") If IsEmpty(FoundCell.Row, "AK") = False Then .Cells(FoundCell.Row, "AK") = .Cells(FoundCell.Row, "AK") Else .Cells(FoundCell.Row, "AK") = Range("M3") If IsEmpty(FoundCell.Row, "AL") = False Then .Cells(FoundCell.Row, "AL") = .Cells(FoundCell.Row, "AL") Else .Cells(FoundCell.Row, "AL") = Range("P3") If IsEmpty(FoundCell.Row, "AM") = False Then .Cells(FoundCell.Row, "AM") = .Cells(FoundCell.Row, "AM") Else .Cells(FoundCell.Row, "AM") = Range("S3") If IsEmpty(FoundCell.Row, "AN") = False Then .Cells(FoundCell.Row, "AN") = .Cells(FoundCell.Row, "AN") Else .Cells(FoundCell.Row, "AN") = Range("V3") If IsEmpty(FoundCell.Row, "AO") = False Then .Cells(FoundCell.Row, "AO") = .Cells(FoundCell.Row, "AO") Else .Cells(FoundCell.Row, "AO") = Range("Y3") End If Set FoundCell = .Columns(1).FindNext(FoundCell) Loop While FoundCell.Address <> FAdr End If End With For i = 1 To 22 Step 3 Range(Cells(3, i), Cells(4, i + 2)).ClearContents Next End Sub