Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/28.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Excel 鉴于我已经循环我的工作表来生成一些数据,如何以更有组织的方式对这些数据进行排序?_Excel_Vba - Fatal编程技术网

Excel 鉴于我已经循环我的工作表来生成一些数据,如何以更有组织的方式对这些数据进行排序?

Excel 鉴于我已经循环我的工作表来生成一些数据,如何以更有组织的方式对这些数据进行排序?,excel,vba,Excel,Vba,因此,我的程序的工作原理是,它将在所有这些工作表中循环查找无效/失败数据,然后最终结果将从第1行A列开始粘贴。count/countini/countinv分别表示rel/initial/invalid失败的次数。让我们假设我有4个工作表,即“devicea”、“deviceb”、“devicec”和“deviced”,以循环获取每个工作表中的rel/initial/invalid fails数据数(A列最左边的数字)。如何提取与计数名称位于同一单元格中的工作表名称,如示例所示,如果计数名称为“

因此,我的程序的工作原理是,它将在所有这些工作表中循环查找无效/失败数据,然后最终结果将从第1行A列开始粘贴。count/countini/countinv分别表示rel/initial/invalid失败的次数。让我们假设我有4个工作表,即“devicea”、“deviceb”、“devicec”和“deviced”,以循环获取每个工作表中的rel/initial/invalid fails数据数(A列最左边的数字)。如何提取与计数名称位于同一单元格中的工作表名称,如示例所示,如果计数名称为“rel”(第A列第5行),如何提取工作表设备d的名称,不仅针对我的案例,而且针对所有案例,并像图片后面部分所示那样组织它们

If Count >= 1 Then
Sheets(1).Cells(Rows.Count, 19).End(xlUp).Offset(1, 0) = Count & " REL Failures in " & ActiveSheet.Name & " !"

If countini >= 1 Then
Sheets(1).Cells(Rows.Count, 19).End(xlUp).Offset(1, 0) = countini & " Initial Failures in " & ActiveSheet.Name & " !"
end if

If countinv >= 1 Then
Sheets(1).Cells(Rows.Count, 19).End(xlUp).Offset(1, 0) = countinv & " Invalid Data points in " & ActiveSheet.Name & " !"
endif
“^A列用于生成输出的上述行块。只需知道变量;计数=rel故障数,计数INI=初始故障数,计数INV=无效数据点数。下面的代码正是我所关心的,需要帮助

Dim lastrow1 As Long

lastrow1 = Sheets(1).Range("A" & Rows.Count).End(xlUp).Row

For Row = 2 To lastrow1

mytext1 = Count & Sheets(1).Range("A" & Row).Value
' for the case of rel fails

If mytext1(2) = "rel" Then

'get the worksheetname that lies the same cell as "REL"
mytext1(4)=

这就是我在评论中的意思,只需在创建左侧文本的同时创建表格即可。我假设Count/countini/countinv不是空的,而是0?如果没有,你需要做一个If语句或其他什么

If Count >= 1 Then
Sheets(1).Cells(Rows.Count, 19).End(xlUp).Offset(1, 0) = Count & " REL Failures in " & ActiveSheet.Name & " !"
'You sure, you dont need an end if here?

If countini >= 1 Then
Sheets(1).Cells(Rows.Count, 19).End(xlUp).Offset(1, 0) = countini & " Initial Failures in " & ActiveSheet.Name & " !"
end if

If countinv >= 1 Then
Sheets(1).Cells(Rows.Count, 19).End(xlUp).Offset(1, 0) = countinv & " Invalid Data points in " & ActiveSheet.Name & " !"
endif

'This creates the table
Sheets(1).Cells(Rows.Count, 3).End(xlUp).Offset(1, 0) = ActiveSheet.Name

'edited in after your comment:
If Count Like "" Then Count = 0
If countini Like "" Then countini = 0
If countinv Like "" Then countinv = 0

Sheets(1).Cells(Rows.Count, 4).End(xlUp).Offset(1, 0) = Count
Sheets(1).Cells(Rows.Count, 5).End(xlUp).Offset(1, 0) = countini
Sheets(1).Cells(Rows.Count, 6).End(xlUp).Offset(1, 0) = countinv

很难理解你需要什么。你想把左边的文字变成右边的表格吗?如果是这样的话,与其先创建文本字符串,然后创建表格,不如尝试同时创建表格,因为您当时已经拥有了所有数据,我想?@czeskleba是的,我试着把右边的表格从left@czeskleba同时创建一个表是什么意思?如果Count>=1,则以
开始代码,然后
。那是多少?我们是否应该不看你的代码,只从左边的表格中提取你需要的内容?你引用的第一个代码使文本在左边,对吗?那就做吧,那时候也做桌子。伊玛贴了一个答案,来说明我的意思。我刚刚注意到,你的第一个代码缺少一个endif tooah,我明白你的意思了……无论如何,你如何使同一行的单元格为空=0?就像在设备中显示的一行…我的意思是,现在你的建议不会把空的单元格看作是零。当它不是1或更大时,计数和CurnTi空了吗?同样也适用于Curntvi…当它不是1或更大的时候,你使用了大量的if语句,所以我也使用了这个样式。我编辑了答案。