Trouble with Search,Select,Insert Macros - HELP!

newatmacros

New Member
Joined
Jun 23, 2016
Messages
18
Hi Everyone,

As you can tell by my username, I am very new to Excel VBA. I just started really utilizing it when I first realized that I can record a macro; however, as I continued it, realized what a powerful tool it can be for my work place when utilizing various data sheets. So far, many of the blogs posted and the reviews attached to them have been very helpful and have helped me create some great macros that do exactly what I want them to do; however, there is one command that is stumping me.
I need a macro do the following:

Search for certain cells with multiple criteria options. (ie. Beverages, Produce, Cold Food)
Select those cells.
Then, select entire columns of the selected cells.
Then, select Blank cells in the columns selected.
Lastly, enter "0" for all of the blank cells in those columns only.

It is very important that the code can search through the entire worksheet (A:ZZ) for these cells with this criteria as I do not want it dependent that the criteria cells will be in the same locations. Also, it is important that only those blank cells from the specified columns are filled with "0". If any other cells are filled with zero, the entire computations that come after will be skewed.
I have tried constant macros and "If Else Then" macros but I have never gotten any of them to fully work for what I need. If anyone knows how to do this with an "If Else Then" macro, it can be very helpful for other macros I may need to create so I can know what I may doing wrong.
Help?

Thank everyone!
 
So after going over the data again, I found a pattern. The filling of zeros stops with the last filled entry in the column; therefore, if for Column A, the last filled entry is Row 160, no more zeros will continue after that, but if for Column B the last filled entry is 600, the zeros will not continue till after 600.
 
Upvote 0

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Hi Fishboy,
No worries about the lateness of your response. I was not able to get to my worksheet till this week anyways. i just sincerely appreciate your help!
I tried the macro with the correction and it works like a charm, filling blank cells in each column specified; however, for each column the filling of the blank cells just stops randomly. Each stopping point is not concurrent with the other. I counted the filled cells in each column to see if there was a pattern of when the macro stops filling the blank cells; however, there is no pattern. One column can have 80 filled cells while another can only have 20 filled cells.
I looked over the macro and see that you instructed it to do so until the last row; therefore, I am unsure why this may be the case. Any thoughts?
Again, thank you for your help!
Hmmm, that is strange. "LastRow" is recalculated for each column so we should be safe in the knowledge that even if different columns are different lengths then it should still be fine. Are you able to share an example copy of your workbook with us so we can do some testing "in situ"? You can obviously obscure any confidential information by replacing it with X's or by making up data to replace it with instead. If you can share then you will need to upload a copy to a file hosting site such as DropBox, One Drive, Google Drive or similar, then post a link to the file on the forum.
 
Upvote 0
So after going over the data again, I found a pattern. The filling of zeros stops with the last filled entry in the column; therefore, if for Column A, the last filled entry is Row 160, no more zeros will continue after that, but if for Column B the last filled entry is 600, the zeros will not continue till after 600.
Why would you need zeroes going beyond the last row? If this is definitely required then is there a fixed "end row" you want all columns to reach?
 
Upvote 0
Hi Fishboy,
I need zeros to go beyond the last row of those columns because the last row of data in those columns do not necessarily dictate that is the last row of data for the rest of the columns which are all correlating with one another.
Example: So since I have A2:A800 = Accounts then even if T column has last data at T365, therefore zeros only go up to T364. This means the rest of my accounts A366:A800 do not have corresponding zeros. They are all left blank in column T.
If I can get the blanks to fill all the way through based on column A, then I am guaranteed that all of my accounts have corresponding data.

I hope that makes sense. Again, thank you so much for your help!
 
Upvote 0
If there is a way to determine fixed end row based on the header of a column that would be even better due to the data sometimes not being structured around column A being the accounts.
 
Upvote 0
If there is a way to determine fixed end row based on the header of a column that would be even better due to the data sometimes not being structured around column A being the accounts.
Are you saying that column A (the list of accounts) could always be used to determine the last row?
 
Upvote 0

Forum statistics

Threads
1,221,310
Messages
6,159,176
Members
451,543
Latest member
cesymcox

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top