Advertisement
Guest User

Untitled

a guest
Mar 18th, 2025
29
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. ' Set the range of visible cells to be copied
  2. Set visibleCells = ws.Range("A6:EF" & lastRow)
  3.  
  4. fullArray = visibleCells.value
  5.  
  6. ' Initialize filteredArray with the same number of columns as fullArray
  7. ReDim filteredArray(1 To UBound(fullArray, 1), 1 To UBound(fullArray, 2))
  8.  
  9. j = 1 ' Row index for filteredArray
  10.  
  11. For i = 1 To UBound(fullArray, 1)
  12. If fullArray(i, 2) = "Value I want" Then
  13. filteredArray(j, 1) = fullArray(i, 1)
  14. filteredArray(j, 2) = fullArray(i, 2)
  15. ' Copy other columns as needed
  16. j = j + 1
  17. End If
  18. Next i
  19.  
  20. ReDim Preserve filteredArray(1 To j - 1, 1 To UBound(fullArray, 2))
  21.  
  22. ' Activate the target worksheet
  23. targetws.Activate
  24.  
  25. ' Debug print the size of the range
  26. Debug.Print "Number of total rows: " & UBound(fullArray, 1)
  27. Debug.Print "Number of total columns: " & UBound(fullArray, 2)
  28. Debug.Print "Number of filtered rows: " & UBound(filteredArray, 1)
  29. Debug.Print "Number of filtered columns: " & UBound(filteredArray, 2)
  30.  
  31. ' Define the target range in the target worksheet and copy the data
  32. Set targetRange = targetws.Range("C6").Resize(filteredArray.Rows.Count, filteredArray.Columns.Count)
  33. targetRange.value = filteredArray.value
  34.  
  35. Immediate
  36. Number of total rows: 46680
  37. Number of total columns: 136
  38. Number of filtered rows: 46680
  39. Number of filtered columns: 136
  40.  
  41.  
  42.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement