代替機能へ - 信頼できない - この答えは完全シャイラドーの感謝を溶液に意向SpecialCells(xlCellTypeVisible)
、それを修正していません。
しかし、上記のソリューションをテストすると、SpecialCells(xlCellTypeVisible)
および/またはCurrentRegion
を参照すると、(OPの小さな範囲内であっても)問題が発生する可能性があります。
可能な回避策(udfsの場合)は、SpecialCells(xlCellTypeVisible) not working in UDFにあります。
Private Function VisibleCells(rng As Range) As Range
' Site: https://stackoverflow.com/questions/43234354/specialcellsxlcelltypevisible-not-working-in-udf
' Note: as proposed by CalumDA
Dim r As Range
For Each r In rng
If r.EntireRow.Hidden = False Then
If VisibleCells Is Nothing Then
Set VisibleCells = r
Else
Set VisibleCells = Union(VisibleCells, r)
End If
End If
Next r
End Function
(ノートの上を参照)シャイラドーのソリューションは、わずかに変更された
いずれの場合も、対象範囲は、あなたがそのようは、コピーして、より良いCurrentRegion
ないで参照する前にをクリアする必要があります希望のアイテムのみを入手してください。これらの変更は私のために働いた。引用した記事で言及
Option Explicit
Private Sub cmdFilteredData_Click()
Dim ws As Worksheet
Dim sRng As String
Dim FilteredRange As Range
Dim myArr As Variant
Dim n As Long
Set ws = ThisWorkbook.Worksheets("Filtered")
n = ws.Range("A" & ws.Rows.Count).End(xlUp).Row ' get last row
sRng = "A1:C" & n
' Set FilteredRange = ws.Range(sRng).SpecialCells(xlCellTypeVisible) ' << not reliable
Set FilteredRange = VisibleCells(ws.Range(sRng)) ' <<<< possible ALTERNATIVE
' clear target range in order to allow correct array fillings later !
ws.Range("Z:AAB").Value = ""
' copy filtered range to the columns on the right
FilteredRange.Copy ws.Range("Z1")
' populate the array with new range values (without blank rows in the middle)
' myArr = ws.Range("Z1").CurrentRegion ' sometimes unreliable, too
myArr = ws.Range("Z1:AAB" & ws.Range("Z" & ws.Rows.Count).End(xlUp).Row) ' <<< better than CurrentRegion
With Me.ListBox1
.ColumnCount = 3
.MultiSelect = fmMultiSelectExtended
.List = (myArr)
End With
End Sub
リンク:
Microsoft - udf not working
ExcelForum - xlCelltypeVisible not working
MrExcel - SpecialCells not working
私はあなたのコードサーバ私の目的として、あなたの答えを受け入れます。また、vbaコードを使用して、事前コピーの 'Copy To'フェザーで達成することもできます。あなたの努力に感謝します。 – harun24hr
「SpecialCells」は、この小さな例の範囲内であっても、信頼できない(https://stackoverflow.com/questions/43234354/specialcellsxlcelltypevisible-not-working-in-udf参照)として知られているようです。オフセット(0、25).Value = "" ' –