我正在使用"文件夹选择对话"选择文件夹。现在我想搜索特定列 所有工作簿。如果匹配则依赖所有行值应在当前活动工作簿中获取。
例如,如果匹配则它将使用所有工作簿中的case语句检查日期列,然后它只显示一行的值。我认为循环中存在问题或Rows.End(xlDown).Value
。
非常感谢您的帮助或帮助。提前谢谢。
Option Explicit
Sub ExtractFigures2()
Dim WSDest As Worksheet
Dim WB As Workbook
Dim WS_Src As Worksheet
Dim Shp As Shape
Dim a As Long
Dim lastRow As Long
Dim MyPath As String
Dim FilterStr As String
Dim FN As String
Dim fso, oFolder, oSubfolder, oFile, queue As Collection
Dim xSheet As Worksheet
Application.ScreenUpdating = False
Set WSDest = ThisWorkbook.Worksheets("Sheet1")
With WSDest
lastRow = .Cells(.Rows.Count, "C").End(xlUp).Row + 1
End With
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim fileName, ws As Worksheet
Dim rng As Range
Dim destWB As Workbook
Dim pPath As String
Dim ShellApp As Object
Dim fileNameC As String
Dim Prompt As String
Dim OpenAt As String
Dim col As Variant
Dim I As Integer
Dim rngData As Range
Set ShellApp = CreateObject("Shell.Application").BrowseForFolder(0, Prompt, 0, OpenAt)
On Error Resume Next
MyPath = ShellApp.self.Path
MsgBox MyPath
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
FilterStr = "*.xls*"
'FilterStr = "*.xls*" ' That was in used
'FilterStr = "*.xls?" 'All files
Set fso = CreateObject("Scripting.FileSystemObject")
Set queue = New Collection
queue.Add fso.GetFolder(MyPath)
Do While queue.Count > 0
Set oFolder = queue(1)
queue.Remove 1 'dequeue
'...insert any folder processing code here...
For Each oSubfolder In oFolder.SubFolders
queue.Add oSubfolder 'enqueue
Next oSubfolder
For Each oFile In oFolder.Files
FN = fso.GetFileName(oFile)
If FN Like FilterStr Then
Set WB = Workbooks.Open(oFile, False)
'********************************
'********************************
Set WS_Src = WB.Worksheets("Sheet1")
'If Err.Number <> 0 Then
'''MsgBox "Worksheet does not exist"
'Set WS_Src = WB.Worksheets("Layout ")
'Else
'MsgBox "Worksheet exists"
'End If
'Or WS_Src = WB.Worksheets("Layout ") Or WS_Src = WB.Worksheets("Lay out")
With WS_Src
'Write filename to sheet
WSDest.Range("A" & lastRow) = _
Left(FN, InStr(FN, ".") - 1)
'Range A1:CE1 Have a Column/Parameter Value
'Set col = Worksheets("Sheet1").Range("A1:CE1").Value
For Each col In Worksheets("Sheet1").Range("A1:CE1")
'For Each col In Cells.CurrentRegion.Rows.Count
Select Case col
Case "Date"
WSDest.Range("B" & lastRow) = _
col.Cells.CurrentRegion.Rows.End(xlDown).Value
'col.End(xlDown)
'col.Cells.CurrentRegion.Rows.End(xlDown).Value is giving me value of one row,I want all row value
'col.Value
'Range(Selection, Selection.End(xlUp)).Select
MsgBox Cells.CurrentRegion.Rows.Count
Case "Vendor"
WSDest.Range("C" & lastRow) = _
col.Value
Case "Region ID"
WSDest.Range("D" & lastRow) = _
col.Value
Case "Circle"
WSDest.Range("E" & lastRow) = _
col.Value
Case "BSC ID"
WSDest.Range("F" & lastRow) = _
col.Value
Case "Cell ID"
WSDest.Range("G" & lastRow) = _
col.Value
Case "Sector ID"
WSDest.Range("H" & lastRow) = _
col.Value
Case "City/Town"
WSDest.Range("I" & lastRow) = _
col.Value
Case "Lattude/Longitude"
WSDest.Range("J" & lastRow) = _
col.Value
Case "1X BTSID"
WSDest.Range("K" & lastRow) = _
col.Value
Case "BTS Friendly Name"
WSDest.Range("L" & lastRow) = _
col.Value
Case "Total Usage"
WSDest.Range("M" & lastRow) = _
col.Value
Case "Primary Usage"
WSDest.Range("N" & lastRow) = _
col.Value
Case "SHO Factor"
WSDest.Range("O" & lastRow) = _
col.Value
Case "Access Terminal (AT) Attempts"
WSDest.Range("P" & lastRow) = _
col.Value
Case "Access Terminal (AT) Failures"
WSDest.Range("Q" & lastRow) = _
col.Value
Case "Access Terminal (AT) Fail% (>2%)"
WSDest.Range("R" & lastRow) = _
col.Value
Case "Access Terminal (AT) Blocks"
WSDest.Range("S" & lastRow) = _
col.Value
Case "Access Terminal (AT) Block% (>2%)"
WSDest.Range("T" & lastRow) = _
col.Value
Case "Access Network (AN) Attempts"
WSDest.Range("U" & lastRow) = _
col.Value
Case "Access Network (AN) Failures"
WSDest.Range("V" & lastRow) = _
col.Value
Case "Access Network (AN) Fail% (>2%)"
WSDest.Range("W" & lastRow) = _
col.Value
Case "Access Network (AN) Blocks"
WSDest.Range("X" & lastRow) = _
col.Value
Case "Access Network (AN) Block% (>2%)"
WSDest.Range("Y" & lastRow) = _
col.Value
Case "Total Attempts"
WSDest.Range("Z" & lastRow) = _
col.Value
Case "Total Failures"
WSDest.Range("AA" & lastRow) = _
col.Value
Case "Total Fail% (>2%)"
WSDest.Range("AB" & lastRow) = _
col.Value
Case "Total Blocks"
WSDest.Range("AC" & lastRow) = _
col.Value
Case "Total Block% (>2%)"
WSDest.Range("AD" & lastRow) = _
col.Value
Case "Session Failed Calls"
WSDest.Range("AE" & lastRow) = _
col.Value
Case "Session Failed Calls% (>2%)"
WSDest.Range("AF" & lastRow) = _
col.Value
Case "Session Blocks"
WSDest.Range("AG" & lastRow) = _
col.Value
Case "Session Block% (>2%)"
WSDest.Range("AH" & lastRow) = _
col.Value
Case "Drop Calls"
WSDest.Range("AI" & lastRow) = _
col.Value
Case "DCR% (>5%)"
WSDest.Range("AJ" & lastRow) = _
col.Value
Case "Connection Setup Time (msec)"
WSDest.Range("AK" & lastRow) = _
col.Value
Case "Unicast Access Terminal Identifier (UATI) Requests"
WSDest.Range("AL" & lastRow) = _
col.Value
Case "Unicast Access Terminal Identifier (UATI) Failures"
WSDest.Range("AM" & lastRow) = _
col.Value
Case "Unicast Access Terminal Identifier (UATI) Failures (%) (>2%)"
WSDest.Range("AN" & lastRow) = _
col.Value
Case "Session Configuration Success Rate (<95%)"
WSDest.Range("AO" & lastRow) = _
col.Value
Case "Authentications Attempts"
WSDest.Range("AP" & lastRow) = _
col.Value
Case "Authentications Failures"
WSDest.Range("AQ" & lastRow) = _
col.Value
Case "Authentications Failures (%) (>2%)"
WSDest.Range("AR" & lastRow) = _
col.Value
Case "A13 Idle Transfer Attempts"
WSDest.Range("AS" & lastRow) = _
col.Value
Case "A13 Idle Transfer Failure (%) (>2%)"
WSDest.Range("AT" & lastRow) = _
col.Value
Case "Fwd Slot Occp (%)"
WSDest.Range("AU" & lastRow) = _
col.Value
Case "FTCH Slot Occp (%)"
WSDest.Range("AV" & lastRow) = _
col.Value
Case "CCH Slot Occp%"
WSDest.Range("AW" & lastRow) = _
col.Value
Case "ACH Occp%"
WSDest.Range("AX" & lastRow) = _
col.Value
Case "Avg DRC Request (kbps)"
WSDest.Range("AY" & lastRow) = _
col.Value
Case "Fwd Sector Thrput including Buffering Delay (kbps)"
WSDest.Range("AZ" & lastRow) = _
col.Value
Case "Fwd Data Served Volume (MB)"
WSDest.Range("BA" & lastRow) = _
col.Value
Case "Fwd Data Served Time (sec)"
WSDest.Range("BB" & lastRow) = _
col.Value
Case "Fwd Sector Thrput when Served (kbps)"
WSDest.Range("BC" & lastRow) = _
col.Value
Case "Effective Fwd Sector Thrput (kbps) (>1.2 Mbps)"
WSDest.Range("BD" & lastRow) = _
col.Value
Case "% Utilization"
WSDest.Range("BE" & lastRow) = _
col.Value
Case "Rev Data Received Volume (MB)"
WSDest.Range("BF" & lastRow) = _
col.Value
Case "Rev Data Served Time (sec)"
WSDest.Range("BG" & lastRow) = _
col.Value
Case "Rev Sector Thrput when received (kbps)"
WSDest.Range("BH" & lastRow) = _
col.Value
Case "Effective Rev Sector Thrput (kbps"
WSDest.Range("BI" & lastRow) = _
col.Value
Case "Radio Link Protocal (RLP) Fwd Data Volume (MB)"
WSDest.Range("BJ" & lastRow) = _
col.Value
Case "RLP Fwd ReTrx Bytes (MB)"
WSDest.Range("BK" & lastRow) = _
col.Value
Case "RLP Fwd ReTrx Rate%"
WSDest.Range("BL" & lastRow) = _
col.Value
Case "Ratio of Fwd RLP to PL"
WSDest.Range("BM" & lastRow) = _
col.Value
Case "RLP Rev Data Volume (MB)"
WSDest.Range("BN" & lastRow) = _
col.Value
Case "RLP Rev ReTrx Req Bytes (MB)"
WSDest.Range("BO" & lastRow) = _
col.Value
Case "RLP Rev ReTrx Req Rate%"
WSDest.Range("BP" & lastRow) = _
col.Value
Case "Ratio of Rev RLP to PL"
WSDest.Range("BQ" & lastRow) = _
col.Value
Case "HO Attempts"
WSDest.Range("BR" & lastRow) = _
col.Value
Case "HO Failures"
WSDest.Range("BS" & lastRow) = _
col.Value
Case "HO Failures (%) (>2%)"
WSDest.Range("BT" & lastRow) = _
col.Value
Case "Abis Blocks"
WSDest.Range("BU" & lastRow) = _
col.Value
Case "Max Users (>20)"
WSDest.Range("BV" & lastRow) = _
col.Value
Case "LongTrm Avg RSSI Rise(dB)"
WSDest.Range("BW" & lastRow) = _
col.Value
Case "LongTrm Peak RSSI Rise (dB)"
WSDest.Range("BX" & lastRow) = _
col.Value
Case "Total Users"
WSDest.Range("BY" & lastRow) = _
col.Value
Case "Date Of Integration"
WSDest.Range("BZ" & lastRow) = _
col.Value
Case "No. of Carriers"
WSDest.Range("CA" & lastRow) = _
col.Value
Case "Cell Call Traffic (Erl)"
WSDest.Range("CB" & lastRow) = _
col.Value
Case "Cell Softer Handoff Traffic (Erl)"
WSDest.Range("CC" & lastRow) = _
col.Value
Case "Cell Soft Handoff Traffic (Erl)"
WSDest.Range("CD" & lastRow) = _
col.Value
Case "% Data Loading"
WSDest.Range("CE" & lastRow) = _
col.Value
End Select
Next
WB.Close False
lastRow = lastRow + 1
End With
End If
Next oFile
Loop
Application.ScreenUpdating = True
End Sub
答案 0 :(得分:0)
如果要在LastRow中为特定列指定变量col的值,请检查以下代码:
WSDest.Range("B" & lastRow) = col.End(xlDown).Value
可以说, col 代表范围Range("A1:CE1")
中的单元格 A1 ,然后col.End(xlDown).Value
将为您提供列的最后一行的值,该值将分配给WSDest.Range("B" & lastRow)