• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Last filled row of the Table

S P P

Member
Is there a way to simplify this VBA

>>> use code - tags <<<
Code:
Dim myRange As Range: Set myRange = Worksheets(1).ListObjects(1).ListColumns(1).DataBodyRange
Dim myRange1 As Range: Set myRange1 = Worksheets(1).ListObjects(1).ListColumns(2).DataBodyRange
Dim myArray As Variant: myArray = IIf(myRange.Rows.Count = 1, Array(myRange), Application.Transpose(myRange))
Dim myArray1 As Variant: myArray1 = IIf(myRange1.Rows.Count = 2, Array(myRange1), Application.Transpose(myRange1))
Dim Y As Long

For Y = LBound(myArray) To UBound(myArray): Range("B3").Value = myArray(Y)
Next
For Y = LBound(myArray1) To UBound(myArray1): Range("C3").Value = myArray1(Y)
Next
 
Last edited by a moderator:
Again without following at least forum rules I just can say just allocate directly the expected result rather than using useless variables & loops …​
 
According to the attachment, according to Excel Objects Model so without any useless variable neither any useless loop :​
Code:
Private Sub Worksheet_Activate()
   With Planilha1.ListObjects(1).ListRows
        [B3:E3] = .Item(.Count).Range.Value
   End With
End Sub
Do you like it ? So thanks to click on bottom right Like !​
 
rlv01

15 Columns

10
>>> as You've noted many times <<<
>>> use code - tags <<<

Code:
For Y = LBound(myArray1) To UBound(myArray1): Range("C3").Value = myArray1(Y)
Next
 
Last edited by a moderator:
Back
Top