Listbox keeps moving

rickblunt

Well-known Member
Joined
Feb 18, 2008
Messages
609
Office Version
  1. 2019
Platform
  1. Windows
Hello,
I am using the sub below to populate a listbox (named "RepairHistory") that I have embedded in a worksheet, the code works fine but the issue is that every time I run the macro the listbox moves a few pixels up and to the left. I do not understand why it is doing that, has anyone ever had this issue before? I need to stop this from happening so I appreciate any insights - thanks,

VBA Code:
Sub RepairHistoryButton_Click()

 Dim sh As Object, sh2 As Worksheet
  Dim i As Long
  
  Set sh = Sheets("Plant Status")
  Set sh2 = Sheets("Repair Log")
    
  sh.RepairHistory.Clear
  For i = 1 To sh2.Range("A" & Rows.Count).End(3).Row
    If sh2.Range("A" & i).Value = sh.RepairedDevice.Value Then
      With sh.RepairHistory
        .AddItem
        .List(.ListCount - 1, 0) = sh2.Cells(i, 2).Value
        .List(.ListCount - 1, 1) = sh2.Cells(i, 3).Value
        .List(.ListCount - 1, 2) = sh2.Cells(i, 4).Value
        .List(.ListCount - 1, 3) = sh2.Cells(i, 5).Value
        .List(.ListCount - 1, 4) = sh2.Cells(i, 6).Value
        .List(.ListCount - 1, 5) = i
       End With
    End If
  Next
        

End Sub
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
When in design mode:
1. Right click on listbox and choose Format Control
2. Choose Don't move or size with cells.
No Vba Required
 
Upvote 0
When in design mode:
1. Right click on listbox and choose Format Control
2. Choose Don't move or size with cells.
No Vba Required
,
Yes, even though there are no cells being adjusted that was the first thing that I did (just in case) but that did not work. The weird thing is that as the macro runs the listbox does not move as it is being populated, it seemingly moves at the very end of the routine.

Also, it will only do it the first time the macro runs, if I repeat the sub over and over the listbox will not continue to move each time - just the first time it is run. What in the world is it that is calling for this object to move? If it was the sub then I would think it would do it every time. I am wondering if it is one of the listbox properties but I am not calling the location parameter in any code.

I have never seen this happen before and it really is a head scratcher...
 
Upvote 0
You said:
the listbox moves a few pixels up and to the left.

How can you even notice a pixel
 
Upvote 0
Change the IntegralHeight property of the listbox to False

1645761324291.png
 
Upvote 0
Solution
You said:
the listbox moves a few pixels up and to the left.

How can you even notice a pixel
well, I was using "pixel" as a general term. I would estimate that it moves left - 10pt, and up about 30pt. It ends up out of alignment with other objects and partially covers a commandbutton. It is always the same amount when it shifts.
 
Upvote 0

Forum statistics

Threads
1,214,923
Messages
6,122,286
Members
449,076
Latest member
kenyanscott

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