(Solved) – Setting textbox values in VBA for excel in a UserForm only works on every other attempt

(solved)-–-setting-textbox-values-in-vba-for-excel-in-a-userform-only-works-on-every-other-attempt

I’m currently building a macro that when you dobbeltclick a cell, it opens a userform with textboxes. I then populate the textboxes with data from the row the cell you clicked is in.

My problem is:
When I dobbeltclick the cells in row 4 it opens a UserForm with blank textboxess.
If I then dobbeltclick another cell in that row it opens the UserForm with the cells filled out correctly.

Then if I dobbeltclick a cell in another row, it opens the userform with the data from the previous row.

Again, if I dobbeltclick another cell in the same row, it opens correctly.

My code is as follows:

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)

        If Intersect(Target, Range("N1:N200", "B3:O200")) Is Nothing Then Exit Sub

        Selection.Select
        currentRow = Selection.Row


        redigerskadeForm.Show

        redigerskadeForm.SagsNrTextbox.value = ActiveSheet.Range("B" & currentRow).value
        redigerskadeForm.referenceTextbox.value = ActiveSheet.Range("C" & currentRow).value
        redigerskadeForm.sagstypeComboBox.value = ActiveSheet.Range("D" & currentRow).value
        redigerskadeForm.adresseTextbox.value = ActiveSheet.Range("E" & currentRow).value
        redigerskadeForm.postTextbox.value = ActiveSheet.Range("F" & currentRow).value
        redigerskadeForm.kontaktTextBox.value = ActiveSheet.Range("G" & currentRow).value
        redigerskadeForm.tlf1Textbox.value = ActiveSheet.Range("H" & currentRow).value
        redigerskadeForm.tlf2Textbox.value = ActiveSheet.Range("I" & currentRow).value
        redigerskadeForm.mailTextbox.value = ActiveSheet.Range("J" & currentRow).value
        redigerskadeForm.ansvarComboBox.value = ActiveSheet.Range("K" & currentRow).value
        redigerskadeForm.opDatoTextbox.value = ActiveSheet.Range("L" & currentRow).value
        redigerskadeForm.foDatoTextbox.value = ActiveSheet.Range("M" & currentRow).value
        redigerskadeForm.statusComboBox.value = ActiveSheet.Range("N" & currentRow).value
        redigerskadeForm.noteTextbox.value = ActiveSheet.Range("o" & currentRow).value



End Sub

Leave a Reply

Your email address will not be published. Required fields are marked *