a = ThisWorkbook.Sheets(1).ListObjects(1).DataBodyRange.Value For i = 1 To UBound(a) Select Case a(i, 1) Case "MaterialRate", "Mat.no", "Articleno", "Article Description", "Date of report", "Article Thk", "ManufSiteCode" x = x + 1 a(x, 1) = a(i, 119) a(x, 2) = a(i, 122) a(x, 3) = a(i, 123) a(x, 4) = a(i, 124) a(x, 5) = a(i, 126) a(x, 6) = a(i, 127) End Select Next With Workbooks("1.xlsx").Sheets("Price Data") .[A1].End(xlDown)(2).Resize(x, 5) = a End With End Sub
[/vba]
Должен переносить колонки по нажатию кнопки Generate.
Почему выходит debug?
Всем доброго времени суток!
Пытаюсь написать код:
[vba]
Код
Sub load_data() Dim a, i&
a = ThisWorkbook.Sheets(1).ListObjects(1).DataBodyRange.Value For i = 1 To UBound(a) Select Case a(i, 1) Case "MaterialRate", "Mat.no", "Articleno", "Article Description", "Date of report", "Article Thk", "ManufSiteCode" x = x + 1 a(x, 1) = a(i, 119) a(x, 2) = a(i, 122) a(x, 3) = a(i, 123) a(x, 4) = a(i, 124) a(x, 5) = a(i, 126) a(x, 6) = a(i, 127) End Select Next With Workbooks("1.xlsx").Sheets("Price Data") .[A1].End(xlDown)(2).Resize(x, 5) = a End With End Sub
[/vba]
Должен переносить колонки по нажатию кнопки Generate.
Sub load_data() Dim avFiles, x, lr As Long avFiles = Application.GetOpenFilename _ ("Excel files(*.xls*),*.xls*", 1, "Выбрать Excel файлы", , True) If VarType(avFiles) = vbBoolean Then Exit Sub End If lr = 9 For Each x In avFiles Cells(lr, 1).Value = x lr = lr + 1 Next Dim a, i& a = ThisWorkbook.Sheets(1).ListObjects(1).DataBodyRange.Value For i = 1 To UBound(a) Select Case a(i, 1) Case "MaterialRate", "Mat.no", "Articleno", "Article Description", "Date of report", "Article Thk", "ManufSiteCode" x = x + 1 a(x, 1) = a(i, 119) a(x, 2) = a(i, 122) a(x, 3) = a(i, 123) a(x, 4) = a(i, 124) a(x, 5) = a(i, 126) a(x, 6) = a(i, 127) End Select Next End Sub
[/vba]
Что тут не так?
Добил код выбором файла:
[vba]
Код
Sub load_data() Dim avFiles, x, lr As Long avFiles = Application.GetOpenFilename _ ("Excel files(*.xls*),*.xls*", 1, "Выбрать Excel файлы", , True) If VarType(avFiles) = vbBoolean Then Exit Sub End If lr = 9 For Each x In avFiles Cells(lr, 1).Value = x lr = lr + 1 Next Dim a, i& a = ThisWorkbook.Sheets(1).ListObjects(1).DataBodyRange.Value For i = 1 To UBound(a) Select Case a(i, 1) Case "MaterialRate", "Mat.no", "Articleno", "Article Description", "Date of report", "Article Thk", "ManufSiteCode" x = x + 1 a(x, 1) = a(i, 119) a(x, 2) = a(i, 122) a(x, 3) = a(i, 123) a(x, 4) = a(i, 124) a(x, 5) = a(i, 126) a(x, 6) = a(i, 127) End Select Next End Sub