
Originally Posted by
jaslake
Hi Stignone
See if this helps.
Option Explicit
Private Sub MenuButton_Click()
Unload Me
Menu.Show
End Sub
Private Sub UserForm_Initialize()
Dim x As Long
Dim k As Long
Dim j As Long
If MultiPage1.Value = 0 Then x = Sheets("INPUT BS").Range("D10:M50").Rows.Count
ListBox1.List = Sheets("INPUT BS").Range("D10:M50").Value
For k = 1 To x 'rows
For j = 1 To 10 'columns
ListBox1.List(k - 1, j - 1) = VBA.Format(ListBox1.List(k - 1, j - 1), "0")
Next
Next
For j = 1 To 10
Me.Controls("TextBox" & j).Text = ""
Next j
If MultiPage1.Value = 1 Then x = Sheets("INPUT BS").Range("D56:M200").Rows.Count
ListBox2.List = Sheets("INPUT BS").Range("D56:M200").Value
For k = 1 To x 'rows
For j = 1 To 10 'columns
ListBox2.List(k - 1, j - 1) = VBA.Format(ListBox2.List(k - 1, j - 1), "0")
Next
Next
For j = 1 To 10
Me.Controls("TextBox" & j).Text = ""
Next j
If MultiPage1.Value = 2 Then x = Sheets("INPUT BS").Range("D210:M257").Rows.Count
ListBox3.List = Sheets("INPUT BS").Range("D210:M257").Value
For k = 1 To x 'rows
For j = 1 To 10 'columns
ListBox3.List(k - 1, j - 1) = VBA.Format(ListBox3.List(k - 1, j - 1), "0")
Next
Next
For j = 1 To 10
Me.Controls("TextBox" & j).Text = ""
Next j
If MultiPage1.Value = 3 Then x = Sheets("INPUT BS").Range("D263:M282").Rows.Count
ListBox4.List = Sheets("INPUT BS").Range("D263:M282").Value
For k = 1 To x 'rows
For j = 1 To 10 'columns
ListBox4.List(k - 1, j - 1) = VBA.Format(ListBox4.List(k - 1, j - 1), "0")
Next
Next
For j = 1 To 10
Me.Controls("TextBox" & j).Text = ""
Next j
If MultiPage1.Value = 4 Then x = Sheets("INPUT BS").Range("D287:M502").Rows.Count
ListBox5.List = Sheets("INPUT BS").Range("D287:M502").Value
For k = 1 To x 'rows
For j = 1 To 10 'columns
ListBox5.List(k - 1, j - 1) = VBA.Format(ListBox5.List(k - 1, j - 1), "0")
Next
Next
For j = 1 To 10
Me.Controls("TextBox" & j).Text = ""
Next j
End Sub
Private Sub CommandButton1_Click()
Unload Me
End Sub
Private Sub CommandButton2_Click()
Dim j As Long
Dim x As Long
If Me.ListBox1.ListIndex = -1 Then
MsgBox "No Data Selected"
Exit Sub
End If
If Me.TextBox1.Value = "" Then Exit Sub
x = Me.ListBox1.ListIndex + 1 'row index
With Sheets("INPUT BS")
For j = 4 To 13 'columns Start in Column 3 <-----------
.Cells(x, j).Value = Me.Controls("TextBox" & j - 2).Text '<--Start in TextBox1
Next j
End With
Call UserForm_Initialize
End Sub
Private Sub CommandButton3_Click()
Unload Me
End Sub
Private Sub CommandButton4_Click()
Dim j As Long
Dim x As Long
If Me.ListBox2.ListIndex = -1 Then
MsgBox "No Data Selected"
Exit Sub
End If
If Me.TextBox13.Value = "" Then Exit Sub
x = Me.ListBox2.ListIndex + 1 'row index
With Sheets("INPUT BS")
For j = 4 To 13 'columns Start in Column 3 <-----------
.Cells(x, j).Value = Me.Controls("TextBox" & j + 10).Text '<--Start in TextBox13
Next j
End With
Call UserForm_Initialize
End Sub
Private Sub CommandButton5_Click()
Unload Me
End Sub
Private Sub CommandButton6_Click()
Dim j As Long
Dim x As Long
If Me.ListBox3.ListIndex = -1 Then
MsgBox "No Data Selected"
Exit Sub
End If
If Me.TextBox25.Value = "" Then Exit Sub
x = Me.ListBox3.ListIndex + 1 'row index
With Sheets("INPUT BS")
For j = 4 To 13 'columns Start in Column 3 <-----------
.Cells(x, j).Value = Me.Controls("TextBox" & j + 22).Text '<--Start in TextBox25
Next j
End With
Call UserForm_Initialize
End Sub
Private Sub CommandButton7_Click()
Unload Me
End Sub
Private Sub CommandButton8_Click()
Dim j As Long
Dim x As Long
If Me.ListBox4.ListIndex = -1 Then
MsgBox "No Data Selected"
Exit Sub
End If
If Me.TextBox37.Value = "" Then Exit Sub
x = Me.ListBox4.ListIndex + 1 'row index
With Sheets("INPUT BS")
For j = 4 To 13 'columns Start in Column 3 <-----------
.Cells(x, j).Value = Me.Controls("TextBox" & j + 34).Text '<--Start in TextBox37
Next j
End With
Call UserForm_Initialize
End Sub
Private Sub CommandButton9_Click()
Unload Me
End Sub
Private Sub CommandButton10_Click()
Dim j As Long
Dim x As Long
If Me.ListBox5.ListIndex = -1 Then
MsgBox "No Data Selected"
Exit Sub
End If
If Me.TextBox49.Value = "" Then Exit Sub
x = Me.ListBox5.ListIndex + 1 'row index
With Sheets("INPUT BS")
For j = 4 To 13 'columns Start in Column 3 <-----------
.Cells(x, j).Value = Me.Controls("TextBox" & j + 46).Text '<--Start in TextBox49
Next j
End With
Call UserForm_Initialize
End Sub
Private Sub ListBox1_Click()
Dim k As Long
Dim j As Long
Dim Ctrl As Control
For Each Ctrl In Me.Controls
If TypeName(Ctrl) = "TextBox" Then
k = Me.ListBox1.ListIndex 'row selected
' Debug.Print Me.ListBox1.ListIndex
For j = 1 To 10
Me.Controls("TextBox" & j).Text = Me.ListBox1.List(k, j - 1)
Next j
End If
Next Ctrl
If Me.TextBox1.Value = "" Then
MsgBox "Can't Select this Row"
Exit Sub
End If
End Sub
Private Sub ListBox2_Click()
Dim k As Long
Dim j As Long
Dim Ctrl As Control
For Each Ctrl In Me.Controls
If TypeName(Ctrl) = "TextBox" Then
k = Me.ListBox2.ListIndex 'row selected
' Debug.Print Me.ListBox2.ListIndex
For j = 1 To 10
Me.Controls("TextBox" & j + 12).Text = Me.ListBox2.List(k, j - 1) '<--Start in TextBox 13
Next j
End If
Next Ctrl
If Me.TextBox13.Value = "" Then
MsgBox "Can't Select this Row"
Exit Sub
End If
End Sub
Private Sub Listbox3_Click()
Dim k As Long
Dim j As Long
Dim Ctrl As Control
For Each Ctrl In Me.Controls
If TypeName(Ctrl) = "TextBox" Then
k = Me.ListBox3.ListIndex 'row selected
' Debug.Print Me.Listbox3.ListIndex
For j = 1 To 10
Me.Controls("TextBox" & j + 24).Text = Me.ListBox2.List(k, j - 1) '<--Start in TextBox 25
Next j
End If
Next Ctrl
If Me.TextBox25.Value = "" Then
MsgBox "Can't Select this Row"
Exit Sub
End If
End Sub
Private Sub Listbox4_Click()
Dim k As Long
Dim j As Long
Dim Ctrl As Control
For Each Ctrl In Me.Controls
If TypeName(Ctrl) = "TextBox" Then
k = Me.ListBox4.ListIndex 'row selected
' Debug.Print Me.Listbox4.ListIndex
For j = 1 To 10
Me.Controls("TextBox" & j + 36).Text = Me.ListBox2.List(k, j - 1) '<--Start in TextBox 37
Next j
End If
Next Ctrl
If Me.TextBox37.Value = "" Then
MsgBox "Can't Select this Row"
Exit Sub
End If
End Sub
Private Sub Listbox5_Click()
Dim k As Long
Dim j As Long
Dim Ctrl As Control
For Each Ctrl In Me.Controls
If TypeName(Ctrl) = "TextBox" Then
k = Me.ListBox5.ListIndex 'row selected
' Debug.Print Me.Listbox5.ListIndex
For j = 1 To 10
Me.Controls("TextBox" & j + 48).Text = Me.ListBox2.List(k, j - 1) '<--Start in TextBox 48
Next j
End If
Next Ctrl
If Me.TextBox49.Value = "" Then
MsgBox "Can't Select this Row"
Exit Sub
End If
End Sub
This should work using your example. But again getting error 381
Bookmarks