1、筛选指定列获取数据
For Each Rng In Sheets("目录").Range("b1:B23")
Debug.Print Rng.Value
If Rng.Value = "个人" Then
n = n + 1
Sheets("备注").Cells(n, "g").Resize(1, 5) = Rng.Offset(0, -1).Range("a1:e1").Value
Sheets("备注").Cells(n, "g").Resize(1, 5) = Rng.EntireRow.Range("a1:e1").Value
End If
Next
2、获取指定杭内容
'On Error Resume Next
Application.ScreenUpdating = False
'MP = ActiveWorkbook.Path
MP = "C:\Users\HONORS\Desktop\(安智)杭实物联网进出库汇总表 总.xlsx" '工作簿路径
'MN = Dir(MP & "\" & "*.xlsx") '工作簿路径
' Set Wb = Workbooks.Open(MP & "\" & MN)
Set Wb = Workbooks.Open(MP)
For i = 1 To Wb.Sheets.Count
'Cells(i, 1) = Sheets(i).Name
Debug.Print Wb.Sheets(i).Name '获取表名
Next
With Wb.Sheets("总账(诸暨库)")
lr = .Cells(Rows.Count, 1).End(xlUp).Row '获取最后一行
Set rngs = .Range("A1:A" & lr) '确认列
For Each Rng In rngs
' Debug.Print Rng.Value
If Rng.Value Like "2021/11/24" Then
n = n + 1
ThisWorkbook.Sheets("测试").Cells(n, "a").Resize(2, 25) = Rng.EntireRow.Range("a1:y1").Value
ThisWorkbook.Sheets("测试").Cells(n, "z").Value = ActiveSheet.Name
End If
Next
End With
3、调整按模块输出内容:
进出库
Dim k%
'On Error Resume Next
Application.ScreenUpdating = False
'MP = ActiveWorkbook.Path
Name = "(安智)杭实物联网进出库汇总表 总"
Dtransport = "2021/12/17"
MP = "C:\Users\HONORS\Desktop\原始数据\储运数据\" & Name & ".xlsx" '工作簿路径
'MN = Dir(MP & "\" & "*.xlsx") '工作簿路径
' Set Wb = Workbooks.Open(MP & "\" & MN)
Set Wb = Workbooks.Open(MP)
'-----------
' For i = 1 To Wb.Sheets.Count
' 'Cells(i, 1) = Sheets(i).Name
' Debug.Print Wb.Sheets(i).Name '获取表名
'Next
'-----------
last_row_clear = ThisWorkbook.Sheets("进出库").Cells(Rows.Count, 1).End(xlUp).Row '最后一行位置
Debug.Print "行数" & last_row_clear
ThisWorkbook.Sheets("进出库").Rows("5:" & last_row_clear).Delete
'-----------
' For i = last_row_clear To 5 Step -1
'ThisWorkbook.Sheets("进出库").Rows(i).Delete
'Debug.Print "删除" & i & "行"
'Next
'-----------
stockName = Array("总账(镇江库)", "总账(衢州库)", "总账(诸暨库)", "总账(昆山库)", "总账(泉州库)", "总账(武汉库)", "总账(泗阳库)", "总账(全椒库)")
For i = 0 To UBound(stockName)
'Debug.Print i
' If i = 0 Then
' Wb.ActiveSheet.Range("a1:Y3").Copy ThisWorkbook.Sheets("测试").Cells(1, 1) '复制标题
' ThisWorkbook.Sheets("测试").Cells(1, 1).Resize(3, 1) = 1
' End If
With Wb.Sheets(stockName(i))
Wb.Sheets(stockName(i)).Activate '当前工作表激活
lr = .Cells(Rows.Count, "A").End(xlUp).Row '获取最后一行
Set rngs = .Range("A1:A" & lr) '确认列
For Each Rng In rngs
' Debug.Print Rng.Value
If Rng.Value Like Dtransport Then
k = k + 1 '记录条目
Debug.Print "条目" & k & ":" & Rng.Value & ActiveSheet.Name '输出当前工作表内容
last_row = ThisWorkbook.Sheets("进出库").Cells(Rows.Count, 1).End(xlUp).Row '最后一行位置
' n = n + 1 '判断行数
ThisWorkbook.Sheets("进出库").Cells(last_row, "a").Resize(2, 25) = Rng.EntireRow.Range("a1:y1").Value '获取对应条目内容
ThisWorkbook.Sheets("进出库").Cells(last_row, "z").Value = ActiveSheet.Name '写入表格名称
End If
Next
End With
Next
ThisWorkbook.Sheets("进出库").Range("A:L").RowHeight = 15 '行高
' ThisWorkbook.Sheets("进出库").Range("C:C").ColumnWidth = 35 '列宽
Wb.Close False '关闭工作簿
4、获取规定条目内容:
运输
Dim k%
On Error Resume Next
Application.ScreenUpdating = False
'MP = ActiveWorkbook.Path
Name = "脚手架运输台账(热联&安智)12.18"
Dtransport = "2021/12/17"
MP = "C:\Users\HONORS\Desktop\原始数据\储运数据\" & Name & ".xlsx" '工作簿路径
'MN = Dir(MP & "\" & "*.xlsx") '工作簿路径
' Set Wb = Workbooks.Open(MP & "\" & MN)
Set Wb = Workbooks.Open(MP)
'-----------
' For i = 1 To Wb.Sheets.Count
' 'Cells(i, 1) = Sheets(i).Name
' Debug.Print Wb.Sheets(i).Name '获取表名
'Next
'-----------
last_row_clear = ThisWorkbook.Sheets("运输").Cells(Rows.Count, 1).End(xlUp).Row '最后一行位置
Debug.Print "行数" & last_row_clear
ThisWorkbook.Sheets("运输").Rows("3:" & last_row_clear).Delete
stockName = Array("热联")
'For i = 0 To UBound(stockName)
Debug.Print i
' If i = 0 Then接下来的货量,货量预计;
With Wb.ActiveSheet 'Wb.Sheets(stockName(0))
' Wb.Sheets(stockName(0)).Activate '当前工作表激活
lr = .Cells(Rows.Count, "A").End(xlUp).Row '获取最后一行
Set rngs = .Range("D1:D" & lr) '确认列
For Each Rng In rngs
' Debug.Print Rng.Value
If Rng.Value Like Dtransport Then
k = k + 1 '记录条目
Debug.Print "条目" & k & ":" & Rng.Value & ActiveSheet.Name '输出当前工作表内容
last_row = ThisWorkbook.Sheets("运输").Cells(Rows.Count, 1).End(xlUp).Row '最后一行位置
' n = n + 1 '判断行数
ThisWorkbook.Sheets("运输").Cells(last_row, "a").Resize(2, 147) = Rng.EntireRow.Range("a1:EQ1").Value '获取对应条目内容
ThisWorkbook.Sheets("运输").Cells(last_row, "ER").Value = ActiveSheet.Name '写入表格名称
End If
Next
End With
ThisWorkbook.Sheets("运输").Range("A:L").RowHeight = 15 '行高
' ThisWorkbook.Sheets("运输").Range("C:C").ColumnWidth = 35 '列宽
'Next
Wb.Close False '关闭工作簿