Consulting

Results 1 to 5 of 5

Thread: Transfer values from sheet to textbox

  1. #1

    Transfer values from sheet to textbox

    Please help me with my simple problem,

    1 command button + 1 textbox + values in A1:below

    i just want the value in A1 be in the textbox and after pressing the button, next value that i want to appear in my textbox is A2, press again the button and value in textbox change to A3, then A4, A5, A6 and so on until no value found in A column

    sorry i just can't understand/know the logic of this as a i'm only a beginner

  2. #2
    try like
    Private Sub CommandButton1_Click()
    Static rw As Long
    rw = rw + 1
    textbox1 = Range("a" & rw)
    End Sub

  3. #3
    Quote Originally Posted by westconn1 View Post
    try like
    Private Sub CommandButton1_Click()
    Static rw As Long
    rw = rw + 1
    textbox1 = Range("a" & rw)
    End Sub
    thank you sir!, i just change Dim to Static, by the way, what's the difference between the two?
    as i used the Dim it doesn't work but when i tried Static it suddenly worked

    and also, i want to prompt a msgbox when there is no values found in the bottom of the range

  4. #4
    Private Sub CommandButton1_Click() 
        Static rw As Long 
        rw = rw + 1 
        if isempty(range("a" & rw) then
            msgbox "no record in row " & rw
        else
           textbox1 = Range("a" & rw) 
        end if
    End Sub
    what's the difference between the two?
    dim is reinitialised each time a procedure is called, whereas static retains it value between calls

  5. #5
    Quote Originally Posted by westconn1 View Post
    Private Sub CommandButton1_Click() 
        Static rw As Long 
        rw = rw + 1 
        if isempty(range("a" & rw) then
            msgbox "no record in row " & rw
        else
           textbox1 = Range("a" & rw) 
        end if
    End Sub
    dim is reinitialised each time a procedure is called, whereas static retains it value between calls
    thank you for explaining it to me, that's why it remains the value in each cells

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •