Return to combobox after running marco

KlausW

Active Member
Joined
Sep 9, 2020
Messages
378
Office Version
  1. 2016
Platform
  1. Windows
Return to combobox after running marco
Hi, anyone who can help. I use a combobox to search and find items. I transfer them with a VBA code, when I run it the combobox is emptied as it should be. Now I would like the cursor to be in the combobox after the VBA code has been run.
Some who can help.

Best regards

Klaus W
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
after last code runs, simply set focus to the combobox

eg: comboboxname.Setfocus
 
Upvote 0
Hi rabsofty
I can't get it to work. I am using this code, I am not sure where to put the code. Best regards Klaus W
VBA Code:
Sub Prisliste_Overfør_Varer_Klik()
    Application.ScreenUpdating = False
    SetVar
    Dim col As New Collection
    Dim Varelinje As New ClVarelinjer
    Dim vElement
    Dim Cell As Range, iCell As Range
    For Each Cell In rPris
        If Cell.Offset(0, 2) <> "" Then
            With Varelinje
                 .Vare_nr = Cell.Value
                 .Navn = Cell.Offset(0, 1).Value
                 .Antal = Cell.Offset(0, 2).Value
                 .Enhed = Cell.Offset(0, 4).Value
                 .Pris = Cell.Offset(0, 5).Value
                 .Bemærkning = Cell.Offset(0, 10).Value
            End With
        Else
            GoTo Videre
        End If
        For Each iCell In rBestil
            With Varelinje
                If iCell.Value = .Vare_nr Then
                    iCell.Value = .Vare_nr
                    iCell.Offset(0, 1).Value = .Navn
                    iCell.Offset(0, 2).Value = .Antal
                    iCell.Offset(0, 4).Value = .Enhed
                    iCell.Offset(0, 5).Value = .Pris
                    iCell.Offset(0, 5).NumberFormat = "$ #,##0.00"
                    iCell.Offset(0, 6).Value = .Bemærkning
                    iCell.Offset(0, 7).FormulaR1C1 = "=IFERROR(RC[-5]*RC[-2],"""")"
                    iCell.Offset(0, 7).NumberFormat = "$ #,##0.00"
                    GoTo Videre
                ElseIf iCell.Value = "" Then
                    iCell.Value = .Vare_nr
                    iCell.Offset(0, 1).Value = .Navn
                    iCell.Offset(0, 2).Value = .Antal
                    iCell.Offset(0, 4).Value = .Enhed
                    iCell.Offset(0, 5).Value = .Pris
                    iCell.Offset(0, 5).NumberFormat = "$ #,##0.00"
                    iCell.Offset(0, 6).Value = .Bemærkning
                    iCell.Offset(0, 7).FormulaR1C1 = "=IFERROR(RC[-5]*RC[-2],"""")"
                    iCell.Offset(0, 7).NumberFormat = "$ #,##0.00"
                    GoTo Videre
                End If
            End With
        Next
Videre:
        Set Varelinje = New ClVarelinjer
    Next Cell
    Cbox
    'renser antal og bemærkning i prislisten
    ClearOmråde WsPris.Range("C9", WsPris.Range("C6000").End(xlUp))
    ClearOmråde WsPris.Range("K9", WsPris.Range("K6000").End(xlUp))
    '
    Slet_række
    ' sorterer
    Sorter WsBestil.Range("A9", WsBestil.Range("H6000").End(xlUp)), WsBestil.Range("B9", WsBestil.Range("B6000").End(xlUp))
    WsPris.Range("a1").Value = Now()
    ' sætter kanter
    IngenKanter WsBestil, WsBestil.Range("a9", WsBestil.Range("H6000"))
    Kanter WsBestil, WsBestil.Range("a9", WsBestil.Range("H6000").End(xlUp))
    WsPris.Activate
    Application.ScreenUpdating = True
    
  [COLOR=rgb(184, 49, 47)]  ComboBox1.SetFocus[/COLOR]
 
 End Sub
  

Private Sub Cbox()
Dim fCbox As ComboBox
Set fCbox = ComboBox1
fCbox.Value = ""
End Sub
 

Attachments

  • 2023-04-05.png
    2023-04-05.png
    100.3 KB · Views: 6
Upvote 0
Sorry I do not know where to set it in. :cry:
 
Upvote 0
i'm not sure why it does not work, unfortunately I can't run the code on my version (since its the english version)
 
Upvote 0
Got this solution here at the Forum on MrExcel
Me.ComboBox1.Activate
 
Upvote 0
Solution

Forum statistics

Threads
1,214,905
Messages
6,122,172
Members
449,071
Latest member
cdnMech

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