Hello,
Total VBA noob here. My only coding experience is an introductory course in Python on Codecademy. I'm trying to write a macro that aligns the NDC numbers in column A with those in Column C on the Referenced Pivot worksheet in the attached file. The manual procedure is as follows: I scroll down the table until I see a mismatched NDC. I then insert 1x2 cells in the column with the greater NDC and shift the cells below down so that every NDC that appears in both lists is on the same row and every NDC and its total that appears on either but both has blank cells next to it in the opposite columns (A&B or C&D). This is so that I can eventually compare the totals for each NDC. It is the NDCs that need to match, not the totals.
I watched a few VBA tutorials and I think what I need here is a For Each loop with a cell insertion macro inside. I recorded a macro with relative references to insert the cells that I have named "insertcell". The problem is that I have no idea what to declare or set or how to script the macro to trigger when the loop encounters an inequality.
What I need is something like:
For Each row in range A4:D[n]
If cellA[n] > cellC[n] Then
insertcell () at A[n]
ElseIf cellA[n] < cellC[n]
insertcell () at C[n]
(I haven't fully learned VBA syntax yet; the above is just the logic I intend).
Below is what I have so far. The code I wrote doesn't work as I don't know what to declare or set yet; I was really just practicing syntax more than anything. The only thing that works is the macro I recorded at the bottom:
Please Login or Register to view this content.
Bookmarks