Help with listBox item delete.

egraham3

Board Regular
Joined
Jun 14, 2010
Messages
200
I have a listbox.

i add the items like this that are located on my source sheet as shown.

my current code works if i select the first item every time. but any time i pick an item down the list, it adds it, but doesnt delete the selection from the row.
I need help making sure it deletes whatever i select from the source, so my list updates next time i click the macro button.

Code:
Private Sub UserForm_Initialize()

Dim KLastRow As Long, K As Long

    KLastRow = Sheets("Source").Range("F" & Rows.Count).End(xlUp).Row
For K = 1 To KLastRow
        KList.AddItem Sheets("Source").Range("F" & K)
Next K

Private Sub KButton_Click()
ActiveCell.Value = "KR " & KList.Value
Sheets("Source").Cells(KList.ListIndex + 6).Delete xlShiftUp
Unload Me
End Sub
 

Some videos you may like

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop

egraham3

Board Regular
Joined
Jun 14, 2010
Messages
200
i hope this is clear.

so in column F. say i have

A
B
C
D

and B is selected. I want that cell of B deleted so the list now looks like
A
C
D

like i said, right now, it's only deleting correctly if i choose the first value in my listbox
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
75,764
Office Version
365
Platform
Windows
Only deleting correctly from where?

The listbox or the worksheet?

Are you actually deleting the selected item from the listbox?
 

egraham3

Board Regular
Joined
Jun 14, 2010
Messages
200

ADVERTISEMENT

yes, Norie, thank you for responding, I've tried using your setup as you can see from previous posts that i found in search.

since im populating my listbox from column F, that's where my listbox items are being pulled from.
So I want it to delete from the "source" sheet that will then correspond to my listbox items.

but like i said, if i select the first item, it does what i want, posts selected value where i want, and deletes cell in "source" and updates listbox.

But when i select say the 2nd value, it inputs it correctly, but doesn't delete(leaving the 2nd value that i actually want to delete)

hope that helps
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
75,764
Office Version
365
Platform
Windows
Sorry but what setup are you referring to?

What do you want to delete and where from?

You need to be careful when populating from ranges and then deleting things.

You might actually be deleting something but not the something you want to delete.
 

egraham3

Board Regular
Joined
Jun 14, 2010
Messages
200

ADVERTISEMENT

this way of adding items from a range
Code:
Private Sub UserForm_Initialize()
Dim KLastRow As Long, K As Long
KLastRow = Sheets("Source").Range("F" & Rows.Count).End(xlUp).Row
For K = 1 To KLastRow
        KList.AddItem Sheets("Source").Range("F" & K)
Next K
Is there a way to then delete selected item, so it doesn't show in listbox next time macro is ran?

which way do you think is easiest to go about this?

I don't necessarily need to delete from the actual sheet if I don't need to?
i just want the selected item gone from listbox, for next macro run.

what would you recommend?
 
Last edited:

egraham3

Board Regular
Joined
Jun 14, 2010
Messages
200
Norie, is there a way I can maybe describe this better?

i add my items as shown above, and then i need this edited so it deletes the selected value from the listbox and updates, it only deletes the cell(and listbox value) when first value is chosen.

Code:
Private Sub KButton_Click()
ActiveCell.Value = "KR " & KList.Value
Sheets("Source").Cells(KList.ListIndex + 6).Delete xlShiftUp
Unload Me
End Sub
 

egraham3

Board Regular
Joined
Jun 14, 2010
Messages
200
just looking for some guidance, if i have a column with data in it for 80 cells.

i want to put all that data in a listbox. be able to select it, input it where i want(activecell) then delete it, so my listbox is updated next time i run macro.
 

Subscribe on YouTube

Watch MrExcel Video

Forum statistics

Threads
1,106,515
Messages
5,511,746
Members
408,864
Latest member
cmajewsk

This Week's Hot Topics

  • Turn fraction around
    Hello I need to turn a fraction around, for example I have 1/3 but I need to present as 3/1
  • TIme Clock record reformatting to ???
    Hello All, I'd like some help formatting this (Tbl-A)(Loaded via Power Query) [ATTACH type="full" width="511px" alt="PQdata.png"]22252[/ATTACH]...
  • TextBox Match
    hi, I am having a few issues with my code below, what I need it to do is when they enter a value in textbox8 (QTY) either 1,2 or 3 the 3 textboxes...
  • Using Large function based on Multiple Criteria
    Hello, I can't seem to get a Large formula to work based on two criteria's. I can easily get a oldest value based one value, but I'm struggling...
  • Can you check my code please
    Hi, Im going round in circles with a Compil Error End With Without With Here is the code [CODE=rich] Private Sub...
  • Combining 2 pivot tables into 1 chart
    Hello everyone, My question sounds simple but I do not know the answer. I have 2 pivot tables and 2 charts that go with this. However I want to...
Top