PDA

View Full Version : [SOLVED] Transfer values from sheet to textbox



jejeserafico
02-24-2014, 07:02 AM
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 :dunno

westconn1
02-24-2014, 01:02 PM
try like

Private Sub CommandButton1_Click()
Static rw As Long
rw = rw + 1
textbox1 = Range("a" & rw)
End Sub

jejeserafico
02-25-2014, 05:01 AM
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

westconn1
02-25-2014, 01:13 PM
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

jejeserafico
02-26-2014, 07:44 AM
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 :clap2: