2017-04-26 41 views
-2

如果我在圖像中顯示的工作表中填充了數據,我想創建一個二維數組並使用數據填充圖像中所選單元格的數據,即所述第一值和跳過下兩個值,並以此類推,直到陣列的端部,並通過在列如何將工作表中的數據填充到二維數組中

 (i),

相同的方式我提出其中刪除該中間行和列,但對於大型陣列中的溶液(例如1000 * 1000),這需要很多時間,這就是爲什麼我想以另一種方式創建具有上述標準的數組。 這是我用於刪除中間行和列的代碼:

Sub Sorting() 
Dim LastRow As Long 
LastRow = sh.Range("A1", sh.Range("A1").End(xlDown)).rows.count 
For cntr = 1 To LastRow/3 
rows(cntr + 1 & ":" & cntr + 2).EntireRow.Delete 
Next 
Dim LastColumn As Long 
LastColumn = sh.Range("A1").CurrentRegion.Columns.count 
K = LastColumn 
For cntr = 1 To K/3 
Columns(cntr + 1).EntireColumn.Delete 
Columns(cntr + 1).EntireColumn.Delete 
Next 
End Sub enter code here 
+1

使用一個簡單的2×'For'循環,用'第3步'並將值讀取到您的二維數組中 –

+3

1.您是否希望使用基於用戶的選擇值或預設的交錯/偏移量單元格中的值填充數組? 2.除了創建其他人必須重新輸入的樣本數據的漂亮圖像之外,您是否已經完成了**沒有任何步驟**,直接向您提供解決方案? – Jeeped

+0

不是基於用戶的選擇。我做了一個解決方案,刪除中間行和列,但對於大型數組(1000 * 1000檢驗),這需要很多時間,這就是爲什麼我想以另一種方式創建符合上述標準的2Darray –

回答

0

像這樣的東西應該爲你工作:

Sub tgr() 

    Dim ws As Worksheet 
    Dim aData As Variant 
    Dim aResults() As Variant 
    Dim lRow As Long, lCol As Long 
    Dim i As Long, j As Long 
    Dim lRowInterval As Long 
    Dim lColInterval As Long 

    Set ws = ActiveWorkbook.ActiveSheet 
    lRowInterval = 3 
    lColInterval = 3 

    aData = ws.Range("A1").CurrentRegion 
    ReDim aResults(1 To Int(UBound(aData, 1)/lRowInterval), 1 To Int(UBound(aData, 2)/lColInterval)) 

    i = 0 
    For lRow = 1 To UBound(aData, 1) Step lRowInterval 
     i = i + 1 
     j = 0 
     For lCol = 1 To UBound(aData, 2) Step lColInterval 
      j = j + 1 
      aResults(i, j) = aData(lRow, lCol) 
     Next lCol 
    Next lRow 

    'Do what you want with the array aResults here 

End Sub 
+0

輝煌的答案.thx –