Добрый день! Пролистал весь форум, но не нашел то что нужно. Необходимо, что бы из файла Output НЕПУСТЫЕ СТРОКИ из столбцов с С по L переносились в файл Input в диапазон с B по K в первую незаполненную строку. Диапазоны не меняются, а вот количество строк может быть до 1000. Можно отдельно выделить часть макроса, который отвечает за отбор непустых ячеек. Хочу самостоятельно разобраться в нем. Спасибо заранее.
Добрый день! Пролистал весь форум, но не нашел то что нужно. Необходимо, что бы из файла Output НЕПУСТЫЕ СТРОКИ из столбцов с С по L переносились в файл Input в диапазон с B по K в первую незаполненную строку. Диапазоны не меняются, а вот количество строк может быть до 1000. Можно отдельно выделить часть макроса, который отвечает за отбор непустых ячеек. Хочу самостоятельно разобраться в нем. Спасибо заранее.AVI
Sub copyRows() With Application .ScreenUpdating = False .EnableEvents = False .DisplayAlerts = False End With Dim shOutput As Worksheet, wbInput As Workbook, lr1 As Long, j As Long, i As Long Set shOutput = ThisWorkbook.Sheets(1) 'ThisWorkbook.Path & "\Input.xlsx" - 'путь к книге Input, если она лежит в этой же папке. 'Если путь другой, заменить ThisWorkbook.Path & "\Input.xlsx" на полный путь Set wbInput = Workbooks.Open(ThisWorkbook.Path & "\Input.xlsx")
lr1 = shOutput.Cells(Rows.Count, "c").End(xlUp).Row With wbInput.Sheets(1) j = .Cells(Rows.Count, "b").End(xlUp).Row + 1 For i = 2 To lr1 If shOutput.Cells(i, "c") <> "" Then .Cells(j, "b").Resize(, 10) = shOutput.Cells(i, "c").Resize(, 10).Value j = j + 1 End If Next i End With wbInput.Close True
With Application .ScreenUpdating = True .EnableEvents = True .DisplayAlerts = True End With End Sub
[/vba]
AVI, так подойдет? [vba]
Код
Sub copyRows() With Application .ScreenUpdating = False .EnableEvents = False .DisplayAlerts = False End With Dim shOutput As Worksheet, wbInput As Workbook, lr1 As Long, j As Long, i As Long Set shOutput = ThisWorkbook.Sheets(1) 'ThisWorkbook.Path & "\Input.xlsx" - 'путь к книге Input, если она лежит в этой же папке. 'Если путь другой, заменить ThisWorkbook.Path & "\Input.xlsx" на полный путь Set wbInput = Workbooks.Open(ThisWorkbook.Path & "\Input.xlsx")
lr1 = shOutput.Cells(Rows.Count, "c").End(xlUp).Row With wbInput.Sheets(1) j = .Cells(Rows.Count, "b").End(xlUp).Row + 1 For i = 2 To lr1 If shOutput.Cells(i, "c") <> "" Then .Cells(j, "b").Resize(, 10) = shOutput.Cells(i, "c").Resize(, 10).Value j = j + 1 End If Next i End With wbInput.Close True
With Application .ScreenUpdating = True .EnableEvents = True .DisplayAlerts = True End With End Sub
Sub copyRows() With Application .ScreenUpdating = False .EnableEvents = False .DisplayAlerts = False End With Dim shOutput As Worksheet, wbInput As Workbook, lr1 As Long, j As Long, i As Long Set shOutput = ThisWorkbook.Sheets("Итог") 'ThisWorkbook.Path & "\Input.xlsx" - 'путь к книге Input, если она лежит в этой же папке. 'Если путь другой, заменить ThisWorkbook.Path & "\Input.xlsx" на полный путь Set wbInput = Workbooks.Open(ThisWorkbook.Path & "\Обработано.xlsx")
lr1 = shOutput.Cells(Rows.Count, "c").End(xlUp).Row With wbInput.Sheets(1) j = .Cells(Rows.Count, "b").End(xlUp).Row + 1 For i = 2 To lr1 If shOutput.Cells(i, "c") <> "" Then .Cells(j, "b").Resize(, 10) = shOutput.Cells(i, "c").Resize(, 10).Value j = j + 1 End If Next i End With wbInput.Close True
With Application .ScreenUpdating = True .EnableEvents = True .DisplayAlerts = True End With End Sub
[/vba] Сменил имя листа на [vba]
Код
ThisWorkbook.Sheets("Итог")
[/vba] и сразу вылезает ошибка [vba]
Код
If shOutput.Cells(i, "c") <> "" Then
[/vba] Помогите, пожалуйста.
Сама ошибка Run-time error '13': Type mismatch
Manyasha, [vba]
Код
Sub copyRows() With Application .ScreenUpdating = False .EnableEvents = False .DisplayAlerts = False End With Dim shOutput As Worksheet, wbInput As Workbook, lr1 As Long, j As Long, i As Long Set shOutput = ThisWorkbook.Sheets("Итог") 'ThisWorkbook.Path & "\Input.xlsx" - 'путь к книге Input, если она лежит в этой же папке. 'Если путь другой, заменить ThisWorkbook.Path & "\Input.xlsx" на полный путь Set wbInput = Workbooks.Open(ThisWorkbook.Path & "\Обработано.xlsx")
lr1 = shOutput.Cells(Rows.Count, "c").End(xlUp).Row With wbInput.Sheets(1) j = .Cells(Rows.Count, "b").End(xlUp).Row + 1 For i = 2 To lr1 If shOutput.Cells(i, "c") <> "" Then .Cells(j, "b").Resize(, 10) = shOutput.Cells(i, "c").Resize(, 10).Value j = j + 1 End If Next i End With wbInput.Close True
With Application .ScreenUpdating = True .EnableEvents = True .DisplayAlerts = True End With End Sub