需要Excel VBA 424错误对象,以单元格(行、列)为单位。值
这是我的第一个VBA脚本,当我在代码下面摩擦时,我在单元格(行,列)上得到424错误。Value=Val(数据(索引))和单元格(行,列)。Value=data(索引)。我是VBA脚本的大一新生。那么如何修复这个错误呢 非常感谢需要Excel VBA 424错误对象,以单元格(行、列)为单位。值,excel,vba,Excel,Vba,这是我的第一个VBA脚本,当我在代码下面摩擦时,我在单元格(行,列)上得到424错误。Value=Val(数据(索引))和单元格(行,列)。Value=data(索引)。我是VBA脚本的大一新生。那么如何修复这个错误呢 非常感谢 Sub ImportFile() Dim TextLine Dim drng As Range Dim n As Integer Dim row As Long, col As Long Dim inde As Integer Dim data() As String
Sub ImportFile()
Dim TextLine
Dim drng As Range
Dim n As Integer
Dim row As Long, col As Long
Dim inde As Integer
Dim data() As String
Dim BegRow As Long, BegCol As Long
Dim index As Integer
Dim cell As Range
BegRow = 2
BegRow = 1
BegCol = 1
Columns("A").AutoFit
Columns("B").AutoFit
Columns("C").AutoFit
Columns("D").AutoFit
Columns("E").AutoFit
Columns("F").AutoFit
Columns("G").AutoFit
Columns("H").AutoFit
Columns("I").AutoFit
Columns("J").AutoFit
Columns("K").AutoFit
Columns("L").AutoFit
Columns("M").AutoFit
Columns("M").AutoFit
Columns("O").AutoFit
Columns("P").AutoFit
Columns("Q").AutoFit
Columns("R").AutoFit
Columns("S").AutoFit
Columns("T").AutoFit
With Application.FileDialog(msoFileDialogFilePicker)
.Title = "Select txt file"
.Filters.Add "All Files", "*.txt"
.FilterIndex = 2
.AllowMultiSelect = False
.Show
f = Trim(.SelectedItems.Item(1))
Open f For Input As #1
Do While Not EOF(1)
Line Input #1, TextLine
TextLine = DeleteSpace(Trim(TextLine))
data = Split(TextLine, "|")
n = UBound(data)
col = BegCol
For index = 0 To n
If IsNumeric(data(inde)) Then
`**Cells(row, col).Value = Val(data(index))**`
Else
**Cells(row, col).Value = data(index)**
End If
col = col + 1
Next ' Index
col = BegCol
row = row + 1
Loop
Close #1
End With
End Sub
函数DeleteSpace(ByVal str作为字符串)作为字符串
将Strtemp设置为字符串
Strtemp = str
While Replace(Strtemp, " ", " ") <> Strtemp
Strtemp = Replace(Strtemp, " ", " ")
Wend
DeleteSpace = Strtemp
Strtemp=str
替换(Strtemp,“,”)Strtemp时
Strtemp=Replace(Strtemp,“,”)
温德
DeleteSpace=Strtemp
结束功能
`行在使用前未分配值。可能还有其他错误。是否初始化了行
值?另外,使用列(“A:T”)。AutoFit
而不是单个列A)
在哪里初始化行和列的值B)
也可以使用“IsNumeric(data(inde))?在“Inde”@SiddharthRout中缺少一个“X”谢谢,你说得对