VBA Arrays

SharmaAntriksh

New Member
Joined
Nov 8, 2017
Messages
31
Why do i get an error is the last line of this code?

Code:
Sub ExtractingDatawithArrays()
  
  Dim TeamStatus() As Variant, ExtractData() As Variant, Counter As Long
  Dim i As Long, k As Long
  
  TeamStatus = Sheet1.Range("A1").CurrentRegion
  
  For i = 2 To UBound(TeamStatus, 1)
    
    If TeamStatus(i, 30) = "Antriksh Sharma" Then
      Counter = Counter + 1
    
    ReDim Preserve ExtractData(1 To UBound(TeamStatus, 2), 1 To Counter)
    
    For k = LBound(TeamStatus, 2) To UBound(TeamStatus, 2)
        ExtractData(k, Counter) = TeamStatus(i, k)
    Next k
    
    End If
  Next i
  
  Sheet2.Range("A1", Sheet2.Range("A1").Offset(UBound(ExtractData, 2) - 1, UBound(ExtractData, 1) - 1)).Value = WorksheetFunction.Transpose(ExtractData)


End Sub
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
It maybe that you hit the limit for transpose.
Try
Code:
Sub ExtractingDatawithArrays()
  
  Dim TeamStatus() As Variant, ExtractData() As Variant, Counter As Long
  Dim i As Long, k As Long
  
  TeamStatus = Sheet1.Range("A1").CurrentRegion
  ReDim ExtractData(1 To UBound(TeamStatus), 1 To UBound(TeamStatus, 2))
  For i = 2 To UBound(TeamStatus, 1)
    
    If TeamStatus(i, 30) = "Warwickshire" Then
      Counter = Counter + 1
    
    For k = LBound(TeamStatus, 2) To UBound(TeamStatus, 2)
        ExtractData(Counter, k) = TeamStatus(i, k)
    Next k
    
    End If
  Next i
  
  Sheet2.Range("A1", Sheet2.Range("A1").Resize(UBound(ExtractData, 1) - 1, UBound(ExtractData, 2) - 1)).Value = ExtractData


End Sub
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,176
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top