Find current week number from 2 different listboxes

danbates

Active Member
Joined
Oct 8, 2017
Messages
377
Office Version
  1. 2016
Platform
  1. Windows
Hi,

I had a listbox (ListBox1) with all 52 weeks of the year in and @Fluff very kindly supplied me with this code that worked perfectly for me:
Code:
Me.ListBox1.Selected(Application.WeekNum(Date) - 1) = True

But because the listbox was so long I have decided to use 2 listboxes (ListBox1, ListBox2) with 26 weeks in each.

So how can I alter the code so it can search through both lostboxes?

Any help would be appreciated.

Thanks

Dan
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
How about
Code:
   i = Application.WeekNum(Date)
   If i <= 26 Then
      Me.ListBox1.Selected(i - 1) = True
   Else
      Me.ListBox2.Selected(i - 27) = True
   End If
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0
Hi Fluff,

Your code is working still but what I have noticed is when the form is opened the current week number is highlighted in blue but week 1 has an outline around it. When I click on a different number the outline moves.

Is there a way to have the current week number highlighted and with the outline?

Thanks again for your help.

Dan
 
Upvote 0
That sounds like ListBox1 has focus. If you make another control have the focus (change tab stop to zero in the properties) then you won't have that outline.
 
Upvote 0

Forum statistics

Threads
1,223,637
Messages
6,173,488
Members
452,515
Latest member
archcalx

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