Pat_The_Bat
Board Regular
- Joined
- Jul 12, 2018
- Messages
- 83
I'm using the code below to create a master list from a pick list. User put's "x"'s next to any document on the picklist that they want to show up on the master list on the following sheet.
The code is working, but the problem is that it is also continues to add multiple instances of the same document if you run the macro several times.
The user will definitely go back to run the macro additional times, because it is common that you continue to add to this list as you go. I need to make it so that once item is on the list, it doesn't get added again (unless the user resets/clears the list).
I'm going to create a command button that simply clears all the documents added to the list and resets everything back to the beginning, so that should take care of the reset.
For the issue of documents getting added twice, I'm thinking it's an IF statement. Or possibly as I add documents to the list I could create a second step where the code adds the document to the list AND puts an "x" in a hidden column on the Doc Request Sheet. Then adjust the code to check for SpecialCells(xlConstants) in Column B AND Column C. This way if a doc has already been put on the master list, it will have the "x" in column B that the user entered, and it will have the "x" in column C that the macro put in, and in those cases the macro will not add that document to the list. But in the cases where there is user-entered "x" in column B, and there is NOT an "x" in column C, the document WILL get added to the list.
Wondering if I'm on the right track here, and also struggling with the syntax of how to do what I'm describing above.
Sub LR()
Dim LSTROW As Integer
With Sheets("Doc Request").Range("B2:B100").SpecialCells(xlConstants)
.Offset(, -1).Copy
End With
With Worksheets("Doc Checklist")
LSTROW = .Range("C" & .Rows.Count).End(xlUp).Row + 1
'fill next available cell with a new data
.Range("C" & LSTROW).PasteSpecial xlPasteAll
End With
End Sub
The code is working, but the problem is that it is also continues to add multiple instances of the same document if you run the macro several times.
The user will definitely go back to run the macro additional times, because it is common that you continue to add to this list as you go. I need to make it so that once item is on the list, it doesn't get added again (unless the user resets/clears the list).
I'm going to create a command button that simply clears all the documents added to the list and resets everything back to the beginning, so that should take care of the reset.
For the issue of documents getting added twice, I'm thinking it's an IF statement. Or possibly as I add documents to the list I could create a second step where the code adds the document to the list AND puts an "x" in a hidden column on the Doc Request Sheet. Then adjust the code to check for SpecialCells(xlConstants) in Column B AND Column C. This way if a doc has already been put on the master list, it will have the "x" in column B that the user entered, and it will have the "x" in column C that the macro put in, and in those cases the macro will not add that document to the list. But in the cases where there is user-entered "x" in column B, and there is NOT an "x" in column C, the document WILL get added to the list.
Wondering if I'm on the right track here, and also struggling with the syntax of how to do what I'm describing above.
Sub LR()
Dim LSTROW As Integer
With Sheets("Doc Request").Range("B2:B100").SpecialCells(xlConstants)
.Offset(, -1).Copy
End With
With Worksheets("Doc Checklist")
LSTROW = .Range("C" & .Rows.Count).End(xlUp).Row + 1
'fill next available cell with a new data
.Range("C" & LSTROW).PasteSpecial xlPasteAll
End With
End Sub