简体   繁体   中英

how to get a value out of a cell into a userform vba excel

I want to use a value of my active worksheet to put in a userform. This has to be dynamic because in my worksheet i have multiple values. The userform open hisself if you click on a button using a macro.

Here are the pictures of the values that i want to put automatically in my userfrom and also my userform.

Thanx

这是带有值的工作表

[enter image description here][2] enter image description here

In your worksheet (asuming your userform is named UserForm1). Change [your column] to the column number you want to autofire your macro.

Private Sub Worksheet_Change(ByVal Target As Range)
  If UserForm1.Visible And Target.Column = [your column] Then
    call UserForm1.GetCellText(Target.Row)
  End If
End Sub

In your Userform (asuming your textboxes are named TextBox1, TextBox2...).

Sub GetCellText(xRow As Integer)
  Dim i As Byte
  For i = 1 To 7
    Me.Controls("TextBox" & i).Value = Cells(xRow, i)
  Next
End Sub

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM