I have heard of the dislike for using .select in VBA for excel macros, but I am wondering how my particular goal can be achieved without its use? For example, say there is a cell(used as a header) with the value "Commodity". Beneath it, all cells need to have a VLookup function. However, on each and every iteration of the macro, the column will shift (as new columns are added) and new rows will be added (so that newly added rows will need to have the function added as well). How is it possible to consistently locate this Commodity column and find its lowest unfilled row? It is very simple to do using select:
Do Until ActiveCell.Value = "Commodity"
Activecell.offset(0,1).select
loop
Do Until ActiveCell.Value = ""
ActiveCell.offset(1,0).select
loop
Obviously, I would prefer to avoid using this type of syntax, but I do not know how to get around it. All answers I have seen regarding the avoidance of select appear to set, for example, rng = Cell(x,y) or something, but they are always known-location cells. I do not know how to do this without utilizing select to check cell values.
I want to simplify the answer a bit. For example
so you can change your code to
Here are two iterate rows to based on the ActiveCell.
First find the column that your Sting is located, then count the rows beside it, set your range and enter the formula.
Assuming the wanted header IS there, you can use this function:
to be used by your main sub as follows
should the absence of the wanted header be handled, the same function gets a little longer like follows
and its exploitation would consequently take into account the possibility of not founding the wanted header: