我在星号线上得到了错误。我浏览了很多我发现很多我复制了相同的答案,但仍然收到此错误。我不确定我做错了什么。
请帮忙。提前致谢。
Sub splitIntoCsv()
Dim wbIn
Dim wbIn1 As Workbook
Dim header, ranges, range_lower, range_upper, rangeCopy As Variant
Dim rangeVariable As String
Dim commacheck, rows, columns As Integer
Set wbIn = CreateObject("Excel.Application")
wbIn.Workbooks.Add
wbIn.Worksheets(1).Name = "TestData"
Set wbIn1 = Workbooks.Open(Sheet1.Range("B1").Value, True, True)
rows = wbIn1.Sheets(1).UsedRange.rows.Count
columns = wbIn1.Sheets(1).UsedRange.columns.Count
header = Split(ThisWorkbook.Sheets(1).Range("B2").Value, ",")
rangeVariable = ThisWorkbook.Sheets(1).Range("B3").Value
commacheck = InStr(rangeVariable, ",")
If commacheck = 0 Then
rangeVariable = rangeVariable & ","
End If
ranges = Split(rangeVariable, ",")
For i = LBound(ranges) To UBound(ranges) - 1
For j = LBound(header) To UBound(header)
wbIn.Worksheets(1).Cells(1, j + 1).Value = header(j)
Next j
range_lower = Split(ranges(i), "-")(0)
range_upper = Split(ranges(i), "-")(1)
With wbIn1.Sheets(1)
rangeCopy = .Range(.Cells(1 + range_lower, 1), .Cells(1 + range_upper, columns)).Value
End With
With wbIn.Worksheets(1)
*********
.Range(.Cells(1 + range_lower, 1), .Cells(1 + range_upper, columns)).Value = rangeCopy
*********
End With
Next i
wbIn1.Close SaveChanges:=True
wbIn.DisplayAlerts = False
wbIn.Worksheets(1).SaveAs Filename:="D:\RaghuDev\raghu.csv", FileFormat:=xlCSV, CreateBackup:=False
wbIn.Quit
End Sub