我有以下循环在Excel 2016中根据PO#列表创建多个选项卡。 (见下面的代码)
org.apache.kafka.streams.errors.StreamsException: Deserialization exception handler is set to fail upon a deserialization error. If you would rather have the streaming pipeline continue after a deserialization error, please set the default.deserialization.exception.handler appropriately.
at org.apache.kafka.streams.processor.internals.RecordDeserializer.deserialize(RecordDeserializer.java:74)
at org.apache.kafka.streams.processor.internals.RecordQueue.addRawRecords(RecordQueue.java:91)
at org.apache.kafka.streams.processor.internals.PartitionGroup.addRawRecords(PartitionGroup.java:117)
at org.apache.kafka.streams.processor.internals.StreamTask.addRecords(StreamTask.java:546)
at org.apache.kafka.streams.processor.internals.StreamThread.addRecordsToTasks(StreamThread.java:920)
at org.apache.kafka.streams.processor.internals.StreamThread.runOnce(StreamThread.java:821)
at org.apache.kafka.streams.processor.internals.StreamThread.runLoop(StreamThread.java:774)
at org.apache.kafka.streams.processor.internals.StreamThread.run(StreamThread.java:744)
Caused by: org.apache.kafka.common.errors.SerializationException: Size of data received by LongDeserializer is not 8
我还需要使用其他工作簿中的信息填充每个新创建的选项卡(EDI PO Consolidated - 2018.xlsx) (见下面的代码)
Sub CreateSheetsFromAList()
Dim MyRange As Range
Dim dic As Object, c As Range
Dim k As Variant, tmp As String
Set dic = CreateObject("scripting.dictionary")
Set MyRange = Sheets("Instructions").Range("h6")
Set MyRange = Range(MyRange, MyRange.End(xlDown))
Sheets("Template").Visible = True
For Each c In MyRange
tmp = Trim(c.Value)
If Len(tmp) > 0 Then dic(tmp) = dic(tmp) + 1
Next c
For Each k In dic.keys
If Not WorksheetExists(k) Then
Sheets("Template").Copy After:=Sheets(Sheets.Count)
ActiveSheet.Name = k
End If
Next k
End Sub
Public Function WorksheetExists(ByVal WorksheetName As String) As Boolean
On Error Resume Next
WorksheetExists = (Sheets(WorksheetName).Name <> "")
On Error GoTo 0
End Function
我有两个问题:
1)我无法为每个标签更改工作表参考;它总是选择 第1 po#“34535453”
2)你能帮我把这些结合成1个宏。
提前感谢您的帮助
答案 0 :(得分:0)
这是创建这些标签的更简洁方法。
在“指令”选项卡“PO_Start”或其他适当的名称上命名单元格H6。这样,如果您可以在选项卡上插入行或列,而无需在代码中更改对H6的引用。
Sub Create_Sheets()
Dim PO_list, PO As Range
Set PO_list = Range(Sheets("Instructions").Range("PO_Start"), Sheets("Instructions").Range("PO_Start").End(xlDown))
Sheets("Template").Visible = True
For Each PO In PO_list
If Not WorksheetExists(PO) Then
Sheets("Template").Copy After:=Sheets(Sheets.Count)
ActiveSheet.Name = PO
End If
Next PO
End Sub
1)要遍历选项卡,如果您知道您的PO选项卡将始终在选项卡3上启动,您可以像这样遍历表格(包括变量声明):
Sub B_and_B()
Dim ws As Worksheet
Dim i As Integer
For i = 3 To Sheets.Count
Set ws = Sheets(i)
'... rest of code here
Next i
End Sub
否则,如果您希望在书籍和帐单文件中添加除“说明”和“模板”之外的其他工作表,您可以遍历所有工作表,错误检查以查看是否可以将工作表名称转换为“长” “带Clng()
的变量类型。可能比您当前项目所需的更多。
另一个提示: 避免在代码中使用硬编码的单元格地址(“N2058”)。如果您在Consolidated book中过滤采购订单,然后提取某些数据元素,则需要找到采购订单所在的行(在本例中为2058)。
2)要将这些组合成一个宏,您可以创建一个Main子例程,分别调用每个步骤:
Sub Main()
Call Create_Sheets
Call B_and_B
End Sub