Only show values in userform that are within my specified area

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,226
Office Version
  1. 2007
Platform
  1. Windows
Hi,
I am using the code below.
Some info for you.
Table is called Table 2
Headers are in row 3
Row 4 is hidden.
My table is the range A to K
Values at present are A5 to K21 but will grow etc as time goes on.

The code shown loads the customers from the table & allows me to select & deletes a customer.

I make some notes outside of the table BUT when i open the userform these notes are also shown.
How can the code be edited so that only the values in the table are shown thus my notes are not loaded into the userform

See my example photo

Thanks


Rich (BB code):
Private Sub ListBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
  Dim i As Long
  Dim lr As Long
  Dim sh As Worksheet

  Set sh = Sheets("GRASS")
  With ListBox1
    sh.Rows(.ListIndex + 5).Delete
    lr = sh.Range("B" & Rows.Count).End(xlUp).Row
    If lr > 4 Then .RowSource = sh.Name & "!A5:B" & lr
    For i = 0 To .ListCount - 1
      If .Selected(i) Then .Selected(i) = False
    Next
  End With
  Unload RemoveCustomer
  Range("A5").Select
End Sub
 

Attachments

  • EaseUS_2023_07_11_10_45_10.jpg
    EaseUS_2023_07_11_10_45_10.jpg
    30.9 KB · Views: 8
  • EaseUS_2023_07_11_10_45_25.jpg
    EaseUS_2023_07_11_10_45_25.jpg
    28.4 KB · Views: 6

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Maybe this is the code you require.

Rich (BB code):
Private Sub UserForm_Initialize()
  Dim lr As Long
  lr = Sheets("GRASS").Range("B" & Rows.Count).End(xlUp).Row
  If lr > 4 Then ListBox1.RowSource = "GRASS!A5:B" & lr
End Sub
 
Upvote 0
As long as you always have at least one blank line in between your data and notes, try changing this line:
VBA Code:
  lr = Sheets("GRASS").Range("B" & Rows.Count).End(xlUp).Row
to this:
VBA Code:
  lr = Sheets("GRASS").Range("B5").End(xlDown).Row
 
Upvote 0
Solution
Great many thanmks.
I did notice if adding a note on the next line it would become part of the table but couldnt work out the code to start from top as oppose bottom.

All sorted now
 
Upvote 0
You are welcome.
Glad I was able to help.
 
Upvote 0

Forum statistics

Threads
1,215,124
Messages
6,123,190
Members
449,090
Latest member
bes000

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