问题描述
在该网站的出色会员的帮助下,我很好地拥有以下工作代码:
Private Sub Imprtstckbtn_Click()
Dim vR(),vDB
Dim WbCSV As Workbook,Wb As Workbook
Dim Ws As Worksheet
Dim i As Long,n As Integer
Dim vFile As Variant
Application.ScreenUpdating = False
Set Wb = ThisWorkbook
Set Ws = Wb.Sheets(2)
'Select a text file through the file dialog.
'Get the path and file name of the selected file to the variable.
vFile = Application.GetopenFilename("ExcelFile *.txt,*.txt;*.csv",_
Title:="Select CSV file",MultiSelect:=False)
'If you don't select file,exit sub.
If TypeName(vFile) = "Boolean" Then Exit Sub
'The selected text file is imported into an Excel file. format:2 is csv,format:1 is tab
Set WbCSV = Workbooks.Open(Filename:=vFile,Format:=2)
'Bring all the contents of the sheet into an array.
With WbCSV.Sheets(1)
vDB = .UsedRange
For i = 1 To UBound(vDB,1)
'AA column = 27,AP column = 42
If vDB(i,27) = "SO0000" And vDB(i,42) = 0 Then
ElseIf vDB(i,27) = "SR0000" And vDB(i,27) = "WG0000" And vDB(i,42) = 0 Then
Else
'Get the contents corresponding to the dynamic array. Bring the matrix to the inverted state.
n = n + 1
ReDim Preserve vR(1 To 5,1 To n)
vR(1,n) = vDB(i,1)
vR(2,2)
vR(3,3)
vR(4,27)
vR(5,42)
End If
Next i
End With
'Colse the text file
WbCSV.Close (0)
'The dynamic array is recorded in sheet2.Bring the row to the inverted state.
With Ws
.UsedRange.Clear
.Range("a1").Resize(n,5).Value = WorksheetFunction.Transpose(vR)
End With
Worksheets("Sheet2").Columns("A:E").AutoFit
Application.ScreenUpdating = True
End Sub
我现在唯一的问题是正在导入的工作表的A列是股票代码,问题是当我导入它时,删除了前导零或excel将长数字赋予科学价值。我需要将A列导入为文本,以确保excel不会将其归类为数字。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)