Hi,
I am using a macro for this operation but my VBA skills aren’t great. I’ve used the record function to get the first iteration to do the most basic function, and it works, but now I’m trying to add more conditions I can’t do it!
Scenario: A list of books to choose from (a long list) a drop down. Once happy with the choice, you can click a button to add the book to your inventory. However, you only have four slots available. My current code works to add the chosen book to your first slot but that’s it.
Essentially I want the code to be:
If slot 1 is empty, then add the book to slot 1.
Else if slot 2 is empty
Else if slot 3
Else if slot 4
Else do not add book and display message that inventory is full
I'd also like to prevent you adding the same book twice, but realise that could be more difficult.
The final ‘message’ is optional since I currently have a separate formula-based message which advises the inventory is full and not to click the button. I found some instructions on the ISEMPTY command but when I tried to incorporate it, it didn’t work.
This is the VBA I am using to achieve the first step. Note that the two sheets are ‘Books’ and ‘Inventory’, and the blank cells are two rows each, spanning AG5:AN12. If being merged cells is a problem, I could always add the books to another single cell elsewhere and then link it. Also worth noting that I want the inventory to be permanently stored (unless deliberately removed), hence why I have a paste values code in there too.
Sheets("Inventory").Select
Range("AG5:AN6").Select
ActiveCell.FormulaR1C1 = "=Books!R[16]C[-30]"
Range("AG5:AN6").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Range("AG7:AN8").Select
Sheets("Books").Select
Range("C18:N20").Select
Even though I have the logic for this operation, I am just not familiar with the VBA language to get the right commands in the right format etc. Any help appreciated - apart from the additional caveats I don't think it will be that taxing for those with the VBA skills!
I am using a macro for this operation but my VBA skills aren’t great. I’ve used the record function to get the first iteration to do the most basic function, and it works, but now I’m trying to add more conditions I can’t do it!
Scenario: A list of books to choose from (a long list) a drop down. Once happy with the choice, you can click a button to add the book to your inventory. However, you only have four slots available. My current code works to add the chosen book to your first slot but that’s it.
Essentially I want the code to be:
If slot 1 is empty, then add the book to slot 1.
Else if slot 2 is empty
Else if slot 3
Else if slot 4
Else do not add book and display message that inventory is full
I'd also like to prevent you adding the same book twice, but realise that could be more difficult.
The final ‘message’ is optional since I currently have a separate formula-based message which advises the inventory is full and not to click the button. I found some instructions on the ISEMPTY command but when I tried to incorporate it, it didn’t work.
This is the VBA I am using to achieve the first step. Note that the two sheets are ‘Books’ and ‘Inventory’, and the blank cells are two rows each, spanning AG5:AN12. If being merged cells is a problem, I could always add the books to another single cell elsewhere and then link it. Also worth noting that I want the inventory to be permanently stored (unless deliberately removed), hence why I have a paste values code in there too.
Sheets("Inventory").Select
Range("AG5:AN6").Select
ActiveCell.FormulaR1C1 = "=Books!R[16]C[-30]"
Range("AG5:AN6").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Range("AG7:AN8").Select
Sheets("Books").Select
Range("C18:N20").Select
Even though I have the logic for this operation, I am just not familiar with the VBA language to get the right commands in the right format etc. Any help appreciated - apart from the additional caveats I don't think it will be that taxing for those with the VBA skills!