Forum Discussion

Gudkovichich's avatar
Gudkovichich
Copper Contributor
Feb 06, 2020

Can someone explain to me what the following VBA statement means/does

df = Cells.Find(What:="*", LookIn:=xlValues, SearchDirection:=xlPrevious, SearchOrder:=xlByRows).Row

 

ReDim data(1 To df, 2)

 

For i = 1 To df

 

data(i, 2) = Cells(i, 5)

data(i, 1) = Trim(Cells(i, 3)) & Trim(Cells(i, 4))

1 Reply

  • macrordinary's avatar
    macrordinary
    Brass Contributor

    Gudkovichich

    df = Cells.Find(What:="*", LookIn:=xlValues, SearchDirection:=xlPrevious, SearchOrder:=xlByRows).Row
    This chunk of code finds an asterisk ("*") on the spreadsheet, then provides the row where the cell was found.

     

     ReDim data(1 To df, 2)

    This chunk of code creates an array where values from row 1 to the row where the asterisk has been found. The 2 means that the array will store two values per row.

     

    For i = 1 To df

    Increments from the first row up to the row where the asterisk was found.

     

    data(i, 1) = Trim(Cells(i, 3)) & Trim(Cells(i, 4))

    For the first element of the array (for each row), it concatenates the third and fourth column, and trims all spaces.

     

    data(i, 2) = Cells(i, 5)

    For the second element of the array (for each row), it takes the 5th column and adds it to the array.

     

     

     

Resources