简体   繁体   English

应用过滤器后Excel填充单元格范围

[英]Excel fill cell range after applying filter

I want to apply a filter on a set of data, after that I would like to fill a range of data into a range of cells. 我想对一组数据应用过滤器,之后我想将一系列数据填充到一系列单元格中。 But now if this will be done, the last two rows are getting the values of the first cell. 但是现在如果这样做,最后两行将获得第一个单元格的值。

-74.4398 -74.4398
-74.2028 -74.2028
-69.8689 -69.8689
-73.1567 -73.1567
-80.1015 -80.1015
-75.822 -75.822
-75.0529 -75.0529
-75.9859 -75.9859
-79.2546 -79.2546
-72.8093 -72.8093
-71.6604 -71.6604

开始

This is the list of numbers in cell B3 to B13. 这是单元格B3到B13中的数字列表。 One button with the following VBA code behind: 一个按钮后面有以下VBA代码:

Private Sub CommandButton1_Click()

    Dim arr() As Variant
    Dim i As Integer

    ReDim arr(1 To 11, 1 To 1)

    arr(1, 1) = "Hallo"
    arr(2, 1) = "Welt"
    arr(3, 1) = "Holla"
    arr(4, 1) = "verdugón"
    arr(5, 1) = "Hello"
    arr(6, 1) = "World"
    arr(7, 1) = "Ciao"
    arr(8, 1) = "mondo"
    arr(9, 1) = "Salut"
    arr(10, 1) = "terre"
    arr(11, 1) = "Final"

    Worksheets("Sheet1").Range("C3:C13").Value = arr

End Sub

If you now set a filter on cell C2 to just show all values greater than -75 you will get a list like that: 如果您现在在单元格C2上设置一个过滤器,只显示大于-75的所有值,您将获得如下列表:

-74.4398 -74.4398
-74.2028 -74.2028
-69.8689 -69.8689
-73.1567 -73.1567
-72.8093 -72.8093
-71.6604 -71.6604

过滤后

If you now press the button so that VBA code will be executed, you will see that the content in cell C12 and C13 has the same value as in cell C3. 如果现在按下按钮以便执行VBA代码,您将看到单元格C12和C13中的内容与单元格C3中的内容相同。

填充范围

Why does it happened, why does it not fill up the cells with the right content ? 为什么会发生这种情况,为什么它没有用正确的内容填充单元格?

I expected that cell C12 will be 'terre' and C13 'Final'. 我预计细胞C12将是“terre”而C13将是“Final”。

Is that an excel issue / bug ? 这是一个excel问题/错误吗?

EDIT: It is more worst as I thought, I used now a different value for the filter -74 and not only the last entries are incorrect, all are incorrect: 编辑:我认为这是更糟糕的,我现在使用了不同的过滤器值-74,不仅最后的条目不正确,都是不正确的:

新的过滤器应用

我相信它确实是一个错误,它似乎已经存在了一段时间 - 看到这个链接

At first glance I would say it's not a bug, and it's moreso the nature of arrays, however I could be completely wrong. 乍一看,我会说它不是一个bug,而且它更像是数组的本质,但我可能完全错了。 If you were looking for a working solution, I went ahead and created this: 如果您正在寻找可行的解决方案,我继续创建:

Sub Button2_Click()
Dim sht As Worksheet, lastrow As Integer, arr() As Variant
Set sht = ThisWorkbook.Worksheets("Sheet1")
lastrow = sht.Cells(sht.Rows.Count, "B").End(xlUp).Row

arr = Array("Hallo", "Welt", "Holla", "verdugón", "Hello", "World", "Ciao", "mondo", "Salut", "terre", "Final")

For i = 3 To lastrow
    Range("C" & i).Value = arr(i - 3)
Next i
End Sub

之前和之后

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在Excel中应用过滤器后引用同一单元格 - Refer the same cell after applying filter in Excel 语法:将IF应用于Excel中的单元格区域 - Syntax: Applying IF to a cell range in Excel 在Excel VBA中应用过滤器后计算选定单元格的范围 - count the selected range of cells after applying filter in excel vba Excel-VBA:在应用过滤器后获取表中可见单元格的值? - Excel-VBA: Get Value of a Visible Cell in a Table after applying Filter? 在 Excel (VBA) 中应用高级过滤器后如何获取可见行的范围 - How to get the range of the visible rows after applying an advanced filter in Excel (VBA) Excel-在单元格中的日期落入日期范围内时填充单元格 - Excel - fill cell when the date in cell falls within a range of dates Excel,自动填充日期范围,每个日期范围一个单元格 - Excel, Auto Fill Date Range, One Cell each Date Range 将Excel VBA单行宏应用于单元格区域 - Applying an Excel VBA single row macro to a cell range Excel - 有条件地用日期填充单元格,但在填充后保持 static - Excel - Conditionally fill cell with date but remain static after fill Excel:仅根据一个单元格的值或公式填充一系列单元格 - Excel: Fill a range of cells with a value or formula depending on only one cell
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM