Я пытаюсь создать сценарий, который извлекает первые 6 символов столбца (определяется пользователем) и либо вставляет новый столбец, и вставляет эти результаты, либо просто проходит эти результаты по уже существующему column (выбор пользователя), но я продолжаю получать ошибку определения объекта (я отметил строку в коде звездочками).Объект Определенная ошибка в скрипте Excel VBA
Может ли кто-нибудь сказать мне, что я делаю неправильно? Вот мой код
Sub AAC_Extract()
Dim rng As Range, col As Range, arr
Dim sht As Worksheet, shet As Worksheet
On Error Resume Next
Set rng = Application.InputBox(_
Prompt:="Please select the column that contains the Standard Document Number. " & vbNewLine & _
" (e.g. Column A or Column B)", _
Title:="Select Document Number Range", Type:=8)
On Error GoTo 0
hdr = MsgBox("Does your selection contain a header?", vbYesNo + vbQuestion, "Header Option")
Set dest = Application.InputBox(_
Prompt:="Please select the column that you would the AAC to be placed in. " & vbNewLine & _
" (e.g. Column B or Column C)", _
Title:="Select Destination Range", Type:=8)
If dest Is Nothing Then Exit Sub
Set sht = dest.Worksheet
Set shet = rng.Worksheet
'If dest = rng Then
' MsgBox "Your Destination Range can not be the same as your Reference Range. Please choose a valid Destination Range", vbExclamation
' Exit Sub
'End If
On Error GoTo 0
yn = MsgBox("Do you want to insert a new column here?" & vbNewLine & _
"(Choosing 'No' will replace the current cells in your selected range." & vbNewLine & "All data in this range will be permanently deleted.)", vbYesNo + vbQuestion, "Destination Range Options")
LastRow = Worksheets("Sheet1").Cells(Rows.Count, 1).End(xlUp).Row
Application.ScreenUpdating = False
If hdr = vbYes And yn = vbYes Then
dest.Select
With Selection
.EntireColumn.Insert
End With
Set col = sht.Range(sht.Cells(2, dest.Column), _
sht.Cells(sht.Rows.Count, dest.Column).End(xlUp))
Set cols = shet.Range(shet.Cells(2, rng.Column), _
shet.Cells(shet.Rows.Count, rng.Column).End(xlUp))
'Columns = cols.Column
'dest.EntireColumn.Insert
'col = dest.Column
'cols = rng.Column
'For i = 1 To LastRow
'Cells(i, col).Value = Left(Cells(i, cols), 6)
'Next i
'For Each c In col.Cells.Offset(0, -1) 'Offset due to the fact that dest moved when a column was inserted
' i = c.Row
' c.Value = Left(cols.Cells(i - 1), 6) 'Honestly, I'm not sure why I have to subtract 1 from i....i should be the same row as c
'Next c
With col
.Value2 = cols.Value2
.TextToColumns Destination:=.Cells, DataType:=xlFixedWidth, _
FieldInfo:=Array(Array(0, 1), Array(6, 9))
End With
End If
End Sub
Я не вижу '*' Какая линия дает вам неприятности? – Brad
@Brad извините, об этом. Я редактировал сценарий, чтобы показать звездочки. Я не могу придумать, как еще подойти к нему, кроме того, как я его прокомментировал. Я думаю, что если я смогу получить эту часть, я смогу обработать код для остальных 3 булевых. –