SharmaAntriksh
New Member
- Joined
- Nov 8, 2017
- Messages
- 31
[TABLE="class: grid, width: 500, align: left"]
<tbody>[TR]
[TD]Name[/TD]
[TD]Serial Number[/TD]
[TD]Date[/TD]
[TD]Price[/TD]
[TD]Address[/TD]
[TD]Comments[/TD]
[/TR]
[TR]
[TD]A[/TD]
[TD]1[/TD]
[TD]1/1/2019[/TD]
[TD]123[/TD]
[TD]abc[/TD]
[TD]xyz[/TD]
[/TR]
[TR]
[TD]B[/TD]
[TD]2[/TD]
[TD]1/1/2019[/TD]
[TD]123[/TD]
[TD]abc[/TD]
[TD]xyz[/TD]
[/TR]
[TR]
[TD]A[/TD]
[TD]3[/TD]
[TD]1/1/2019[/TD]
[TD]123[/TD]
[TD]abc[/TD]
[TD]xyz[/TD]
[/TR]
[TR]
[TD]C[/TD]
[TD]4[/TD]
[TD]1/1/2019[/TD]
[TD]123[/TD]
[TD]abc[/TD]
[TD]xyz[/TD]
[/TR]
</tbody>[/TABLE]
i have data that looks like this, i am trying to load this into an array and populate a new array with the data where name is "A" i want the new array to only have the columns "Name", "Price", and "Comments". i am able to extract the rows with the help of below code but i am not sure how to keep only the required columns while the loop is running
<tbody>[TR]
[TD]Name[/TD]
[TD]Serial Number[/TD]
[TD]Date[/TD]
[TD]Price[/TD]
[TD]Address[/TD]
[TD]Comments[/TD]
[/TR]
[TR]
[TD]A[/TD]
[TD]1[/TD]
[TD]1/1/2019[/TD]
[TD]123[/TD]
[TD]abc[/TD]
[TD]xyz[/TD]
[/TR]
[TR]
[TD]B[/TD]
[TD]2[/TD]
[TD]1/1/2019[/TD]
[TD]123[/TD]
[TD]abc[/TD]
[TD]xyz[/TD]
[/TR]
[TR]
[TD]A[/TD]
[TD]3[/TD]
[TD]1/1/2019[/TD]
[TD]123[/TD]
[TD]abc[/TD]
[TD]xyz[/TD]
[/TR]
[TR]
[TD]C[/TD]
[TD]4[/TD]
[TD]1/1/2019[/TD]
[TD]123[/TD]
[TD]abc[/TD]
[TD]xyz[/TD]
[/TR]
</tbody>[/TABLE]
i have data that looks like this, i am trying to load this into an array and populate a new array with the data where name is "A" i want the new array to only have the columns "Name", "Price", and "Comments". i am able to extract the rows with the help of below code but i am not sure how to keep only the required columns while the loop is running
Code:
Sub WorkingWithArrays()
Dim OriAry() As Variant 'Will store original data
Dim NewAry() As Variant 'will have the data after satisfying a condition
Dim i As Integer, Counter As Integer, k As Integer
OriAry = Sheet2.Range("A1:F5")
For i = LBound(OriAry, 1) To UBound(OriAry, 1)
If OriAry(i, 1) = "A" Then
Counter = Counter + 1
ReDim Preserve NewAry(LBound(OriAry, 2) To UBound(OriAry, 2), 1 To Counter)
For k = LBound(OriAry, 2) To UBound(OriAry, 2)
NewAry(k, Counter) = OriAry(i, k)
Next k
End If
Next i
Sheet3.Range("A2", Sheet3.Range("A2").Offset(Counter - 1, UBound(NewAry, 1) - 1)) = Application.Transpose(NewAry)
End Sub
Last edited: