amoverton2
Board Regular
- Joined
- May 13, 2021
- Messages
- 77
- Office Version
- 2016
- Platform
- Windows
Hey All!
Background info:
I have a workbook with 12 sheets, 1 sheet labeled 99999 (all data), and individual entities labeled AAA, BBB, CCC, DDD, EEE, FFF, GGG, HHH, III, JJJ, KKK.
I have a vba userform with 14 textboxes (labeled TextBox1-14)
On each of the sheets they are 14 pieces of information in columns A thru N (hence 14 textboxes)
Want:
I want the code to transfer all the information residing in the 14 textboxes to the "all data" sheet (99999) and the sheet specified in TextBox1 (which will be AAA, BBB,...KKK) in the next empty row (on both the "all data" and specified sheet) from column A to N.
Problem:
I've inputted information and clicked the button and the information does not go into the sheets, its like it disappears.
Code:
Thanks!!
Background info:
I have a workbook with 12 sheets, 1 sheet labeled 99999 (all data), and individual entities labeled AAA, BBB, CCC, DDD, EEE, FFF, GGG, HHH, III, JJJ, KKK.
I have a vba userform with 14 textboxes (labeled TextBox1-14)
On each of the sheets they are 14 pieces of information in columns A thru N (hence 14 textboxes)
Want:
I want the code to transfer all the information residing in the 14 textboxes to the "all data" sheet (99999) and the sheet specified in TextBox1 (which will be AAA, BBB,...KKK) in the next empty row (on both the "all data" and specified sheet) from column A to N.
Problem:
I've inputted information and clicked the button and the information does not go into the sheets, its like it disappears.
Code:
VBA Code:
Private Sub CommandButton1_Click()
Dim wsDestination As Worksheet
Dim wsMain As Worksheet
Dim userInput As String
Dim lastRow As Long
Dim i As Integer
userInput = UCase(TextBox1.Value)
Select Case userInput
Case "AAA", "BBB", "CCC", "DDD", "EEE", "FFF", "GGG", "HHH", "III", "JJJ", "KKK"
Set wsDestination = ThisWorkbook.Sheets(userInput)
Case Else
MsgBox "Invalid sheet name entered."
Exit Sub
End Select
With wsDestination
lastRow = .Cells(.Rows.Count, "A").End(xlUp).Row + 1
For i = 2 To 14
.Cells(lastRow, i - 1).Value = Controls("TextBox" & i).Value
Next i
End With
Set wsMain = ThisWorkbook.Sheets("99999")
With wsMain
lastRow = .Cells(.Rows.Count, "A").End(xlUp).Row + 1
.Cells(lastRow, 1).Value = TextBox1.Value ' Assumed to be the sheet name
For i = 2 To 14
.Cells(lastRow, i).Value = Controls("TextBox" & i).Value
Next i
End With
'Clear textboxes after transfer
For i = 1 To 14
Controls("TextBox" & i).Value = ""
Next i
End Sub
Thanks!!
Last edited by a moderator: