Z
Zigball
Hello ,
I am having trouble with the GetData Sub I suppose. This is used in my
userforms to scroll through rows and columns refering to a specific
worksheet. Example: userform1 inputs data into sheet1 then userform1
wants to getdata to display inside of the approiate fields in the
userform. there are four command buttons first, previous, next and
last. there is a text box named rownumber that displays the rownumber
that is being viewed. As before it will work if I am inside the
corresponding sheet but if that sheet is hidden or not selected it will
not work. Would you be able to figure this out? Here is an example of
the code that I have stored in the userform.
The main goal is to have it work while the sheet it is getting data
from is
veryhidden!
_____________________________________________________________________________
Public LastRow As Long
Private Sub GetData()
Dim r As Long
Dim r1 As Range, r2 As Range
Set r1 = Worksheets("sheet1").Range("A1:A100").CurrentRegion
If IsNumeric(RowNumber.Text) Then
r = CLng(RowNumber.Text)
Else
ClearData
MsgBox "Illegal row number"
Exit Sub
End If
If r > 1 And r <= LastRow Then
FirstName.Text = r1.Cells(r, 1)
ElseIf r = 2 Then
ClearData
Else
ClearData
MsgBox "Invalid row number"
End If
End Sub
___________________________________________________________________
Private Sub ClearData()
FirstName.Text = ""
End Sub
____________________________________________________________________
Private Sub RowNumber_Change()
GetData
End Sub
_________________________________________________________________
Private Sub First_Click()
RowNumber.Text = "2"
End Sub
______________________________________________________________________
Private Sub Previous_Click()
Dim r As Long
If IsNumeric(RowNumber.Text) Then
r = CLng(RowNumber.Text)
r = r - 1
If r > 1 And r <= LastRow Then
RowNumber.Text = FormatNumber(r, 0)
End If
End If
End Sub
______________________________________________________________________
Private Sub Next1_Click()
Dim r As Long
If IsNumeric(RowNumber.Text) Then
r = CLng(RowNumber.Text)
r = r + 1
If r > 1 And r <= LastRow Then
RowNumber.Text = FormatNumber(r, 0)
End If
End If
End Sub
________________________________________________________________________
Private Function FindLastRow()
Dim r As Long
r = 2
Do While r < 65536 And Len(Cells(r, 1).Text) > 0
r = r + 1
Loop
FindLastRow = r
End Function
_____________________________________________________________________
I am having trouble with the GetData Sub I suppose. This is used in my
userforms to scroll through rows and columns refering to a specific
worksheet. Example: userform1 inputs data into sheet1 then userform1
wants to getdata to display inside of the approiate fields in the
userform. there are four command buttons first, previous, next and
last. there is a text box named rownumber that displays the rownumber
that is being viewed. As before it will work if I am inside the
corresponding sheet but if that sheet is hidden or not selected it will
not work. Would you be able to figure this out? Here is an example of
the code that I have stored in the userform.
The main goal is to have it work while the sheet it is getting data
from is
veryhidden!
_____________________________________________________________________________
Public LastRow As Long
Private Sub GetData()
Dim r As Long
Dim r1 As Range, r2 As Range
Set r1 = Worksheets("sheet1").Range("A1:A100").CurrentRegion
If IsNumeric(RowNumber.Text) Then
r = CLng(RowNumber.Text)
Else
ClearData
MsgBox "Illegal row number"
Exit Sub
End If
If r > 1 And r <= LastRow Then
FirstName.Text = r1.Cells(r, 1)
ElseIf r = 2 Then
ClearData
Else
ClearData
MsgBox "Invalid row number"
End If
End Sub
___________________________________________________________________
Private Sub ClearData()
FirstName.Text = ""
End Sub
____________________________________________________________________
Private Sub RowNumber_Change()
GetData
End Sub
_________________________________________________________________
Private Sub First_Click()
RowNumber.Text = "2"
End Sub
______________________________________________________________________
Private Sub Previous_Click()
Dim r As Long
If IsNumeric(RowNumber.Text) Then
r = CLng(RowNumber.Text)
r = r - 1
If r > 1 And r <= LastRow Then
RowNumber.Text = FormatNumber(r, 0)
End If
End If
End Sub
______________________________________________________________________
Private Sub Next1_Click()
Dim r As Long
If IsNumeric(RowNumber.Text) Then
r = CLng(RowNumber.Text)
r = r + 1
If r > 1 And r <= LastRow Then
RowNumber.Text = FormatNumber(r, 0)
End If
End If
End Sub
________________________________________________________________________
Private Function FindLastRow()
Dim r As Long
r = 2
Do While r < 65536 And Len(Cells(r, 1).Text) > 0
r = r + 1
Loop
FindLastRow = r
End Function
_____________________________________________________________________