Каждый день я получаю файл Excel с переменным количеством строк и столбцов с разными заголовками.
Макрос копирует всю информацию на листе, переставляет столбцы в определенном порядке c и удаляет ненужные столбцы.
Проблема заключается в том, чтобы скопировать необработанную информацию в 10-й строке (заголовок) и выполнить макрос. Строки выше 10-го ряда также затронуты, и я нуждаюсь в них без изменений.
Я пытался найти решение, но даже если я близко, я не понимаю.
Dim search As Range
Dim counter As Integer
Dim lines As Integer
Dim columnOrder As Variant
Dim position As Integer
'define column order with header names here
columnOrder = Array("ID", "HOUR EXP", "FIRM ORG", "TRADER")
counter = 1
'I want here count how many rows with data are there
lines = Cells(Rows.Count, 10).End(xlUp).Row
'LBound/Ubound indicates how many total headers are there
For position = LBound(columnOrder) To UBound(columnOrder)
Set search = Rows("10:10").Find(columnOrder(position), _
LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByColumns, _
SearchDirection:=xlNext, MatchCase:=False)
If Not search Is Nothing Then
If search.Column <> counter Then
search.EntireColumn.Cut
Columns(counter).Insert Shift:=xlToRight
'-->I'm trying (unsucessfully) here to select only from the found column
' the range beggining at row 10 with various possibilities
'search.Range(Rows("10:" & lines + 10)).Cut
'search.EntireColumn.Cut
'Rows(contador).Insert Shift:=xlToRight
'Cells(contador).Insert Shift:=xlToRight
Application.CutCopyMode = False
End If
counter = counter + 1
End If
Next position
Worksheets("sheet1").ActivateRange("E10", Range("E10").End(xlToRight).End(xlDown)).Delete
End Sub