ActiveX controls

rickblunt

Well-known Member
Joined
Feb 18, 2008
Messages
609
Office Version
  1. 2019
Platform
  1. Windows
Greetings, I have been using userforms for years and I have really enjoyed it - but I have never really tried to put the technique (other than adding command buttons) directly on the worksheets. So I am trying my hand at building a dashboard and I thought that this would be the perfect time to start embedding the controls into the WS instead of calling up a userform. I now realize though that the syntax must be different as the code below is not acting the same as it does in my userform.

Briefly, I use the value in a combobox (RepairedDevice) to sort data and pass it to a listbox (RepairHistory). Works great in my userforms, but nothing really appears to happen other than moving to the Repair Log sheet. I would normally put the code in a module, but I found that I actually had to put it into the WS page module instead for it to even see the objects.

Is it that I am using the objects incorrectly and that the syntax is completely different - or am I missing something simple? Because the code is in the Dashboard WS but the data is in the Repair Log WS leads me to think that I cant pass data between sheets or something like that.

I appreciate your thoughts on this - thank you,




VBA Code:
Sub DashboardRepairs()
    Dim i As Long
    Dim Lastrow As Long
      
 Application.DisplayAlerts = False
        
    Sheets("Repair Log").Select

    Lastrow = Cells(Rows.Count, "A").End(xlUp).Row
         For i = 1 To Lastrow
             If Cells(i, 1).Value = RepairedDevice.Value Then RepairHistory.AddItem Cells(i, 1).Value & " - " + Cells(i, 2).Value & _
             " - " + Cells(i, 3).Value & " - " + Cells(i, 4).Value & " - " + Cells(i, 5).Value
         Next
         
   Sheets("Dashboard").Select
         
 Application.DisplayAlerts = True
  
End Sub
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
As I understand it, the ActiveX Controls are on sheet "Dashboard"
Try this:

VBA Code:
Sub DashboardRepairs()
  Dim sh As Object
  Dim i As Long
  
  Set sh = Sheets("Dashboard")
  With Sheets("Repair Log")
    sh.RepairHistory.Clear
    For i = 1 To .Range("A" & Rows.Count).End(3).Row
      If .Range("A" & i).Value = sh.RepairedDevice.Value Then
        sh.RepairHistory.AddItem .Cells(i, 1).Value & " - " & .Cells(i, 2).Value & " - " & _
                              .Cells(i, 3).Value & " - " & .Cells(i, 4).Value & " - " & .Cells(i, 5).Value
      End If
    Next
  End With
End Sub
 
Upvote 0
Thanks Dante - that worked pretty well. So the syntax is basically the same as what I am used to, with a few nuances - that's good to know; Hopefully I can adapt without much trouble. The only quirk was that it was only transferring over the first two columns, not all five. I have my listbox set for 5 columns, and I gave them all a pretty large width.... So I will have to figure out why only two columns show up - thanks for the help.
 
Upvote 0
Thanks Dante - that worked pretty well. So the syntax is basically the same as what I am used to, with a few nuances - that's good to know; Hopefully I can adapt without much trouble. The only quirk was that it was only transferring over the first two columns, not all five. I have my listbox set for 5 columns, and I gave them all a pretty large width.... So I will have to figure out why only two columns show up - thanks for the help.
Follow up - I figured it out, all five columns on the WS is getting passed to the first column on the listbox, not 5 separate columns like on the WS.
 
Upvote 0
The only quirk was that it was only transferring over the first two columns, not all five. I have my listbox set for 5 columns
For that, try this:

VBA Code:
Sub DashboardRepairs()
  Dim sh As Object, sh2 As Worksheet
  Dim i As Long
  
  Set sh = Sheets("Dashboard")
  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, 1).Value
        .List(.ListCount - 1, 1) = sh2.Cells(i, 2).Value
        .List(.ListCount - 1, 2) = sh2.Cells(i, 3).Value
        .List(.ListCount - 1, 3) = sh2.Cells(i, 4).Value
        .List(.ListCount - 1, 4) = sh2.Cells(i, 5).Value
      End With
    End If
  Next
End Sub
 
Upvote 0
Solution
Sweet - Thanks Dante, one column would work but all 5 is the best (the formatting will look better) best of all I can understand how you are doing it in the code :) Maybe there is hope for me yet - lol.. Thank you for the assistance and yet one more knowledge session.
 
Upvote 0
Nice to hear that. Thanks for the feeedback.
 
Upvote 0

Forum statistics

Threads
1,215,054
Messages
6,122,895
Members
449,097
Latest member
dbomb1414

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