I am attempting to copy and paste text values to a certain amount of cells in excel based on a text comparison.
Please see below for explanation:
I have 2 column A(blank) and B(with values)

After the macros, this will be the end results:

It is basically taking the bottom cell after it detect the fruits column and pasting the cell value into row A. Note that after it reaches the next cell fruits it take the next (bottom) cell value. F123,F124 etc..
Can someone please provide me with the excel vba codes to do? Thanks.
I would not use VBA for this problem. I would type:
into A2 and copy down. This seems to give the effect you seek.
If you really want to use VBA, the tested code is:
The following explains those aspects of the above code that may be obscure to a newbie.
The macro recorder almost always uses Range(“A5”) or Range(“A5:C10”) to refer to ranges.
There appear to be a few commands (sorry, don’t remember which) for which this format is compulsory but for most purposes Cells(Row, Column) is more convenient.
If you want to add 1 to every numeric value in the range “A5:C10” of sheet “Sheet1”, the following shows how to do this with Cells:
There is a time penalty with accessing cells in a worksheet but I have used CellValue more because code can get very cluttered with too many cell references.
Note: in “A5” the column comes first but in Cells(5,1) the row comes first.
You can define ranges with Cells. The following sets “A5:C10” of the active sheet to bold:
To address column A of the last row of the active sheet:
To address the last column of row 1:
Ctrl+Up, Ctrl+Down, Ctrl+Left and Ctrl+Right can be used to jump from an empty cell to the next cell with a value in the indicated direction. You can do the same in VBA. But more usefully you can get the value of the row or column to which the cursor would jump without the time penalty of moving the cursor.
If the cursor was in column B of the last row and you pressed Ctrl+Up, the cursor would jump to the last row with a value in column B. The following sets RowMax to that row number for the active sheet:
To get the last used column of row 27: