bruce24444
New Member
- Joined
- Feb 15, 2010
- Messages
- 40
- Office Version
- 365
- 2019
- Platform
- Windows
I have a multipage userform that when finished, will have a combination of 300+ textboxes, comboboxes, checkboxes, combo and Option buttons to which the enduser may or may not enter information into. Because the end user may or may not be required to enter information in any one particular box, I have coded the userform to check each input area and then return the input information if the input area is greater than “”.
What I’m looking for suggestions on or help on is: Is there anyway I can change my code so that when the user clicks “OK” the code will cycle through each input.value and if the end user has input some information it will enter it on the next empty row without me entering a specific row number for each line of code?
The problem I ran into is that I have coded almost half of the userform and then I realized I missed 2 input sections around Cells(eRow, 102).Value. So in order to have that information show up in the proper order, I entered code for lines Cells(eRow, 102).Value and Cells(eRow, 103).Value, but now have to change every one of the following lines in sequential order.
I know the answer lies within the eRow = Sheet1.Range("A:A").End(xlUp).Row line and the Cells(eRow, 102).Value line, but I just can’t get it to work. All I get is the very last input.value.
As a second part of this question, if I can get the input.value to begin at A15 and then go to A16, A17, …. That will save me transposing the entire thing at the end.
What I’m looking for suggestions on or help on is: Is there anyway I can change my code so that when the user clicks “OK” the code will cycle through each input.value and if the end user has input some information it will enter it on the next empty row without me entering a specific row number for each line of code?
The problem I ran into is that I have coded almost half of the userform and then I realized I missed 2 input sections around Cells(eRow, 102).Value. So in order to have that information show up in the proper order, I entered code for lines Cells(eRow, 102).Value and Cells(eRow, 103).Value, but now have to change every one of the following lines in sequential order.
I know the answer lies within the eRow = Sheet1.Range("A:A").End(xlUp).Row line and the Cells(eRow, 102).Value line, but I just can’t get it to work. All I get is the very last input.value.
As a second part of this question, if I can get the input.value to begin at A15 and then go to A16, A17, …. That will save me transposing the entire thing at the end.
Code:
Private Sub CommandButtonOK_Click()
Dim eRow As Long
'Make Sheet1 Active
Sheets(1).Activate
'Determine eRow
eRow = Sheet1.Range("A:A").End(xlUp).Row
If txt_Inv_Date.Value > "" Then
Cells(eRow, 1).Value = "Invoice Date: " + txt_Inv_Date.Value
End If
If txt_Total_ILE_Amount.Value > "" Then
Cells(eRow, 2).Value = "Total ILE: $" + txt_Total_ILE_Amount.Value
End If
If txt_Meals_Inv.Value > "" Then
Cells(eRow, 3).Value = "Attachment: Meal Receipts #" + txt_Meals_Inv.Value
End If
If txt_Meals_Worksheet.Value > "" Then
Cells(eRow, 4).Value = "Attachment: Meal Receipts Worksheet #" + txt_Meals_Worksheet.Value
End If
If Check_Per_Diem.Value > "" Then
Cells(eRow, 5).Value = "Meal allowance as per diem"
End If
'and so on ....... up to
If opt_Pay_Close.Value = True Then
Cells(eRow, 326).Value = "Report concluded - CLOSE file"
End If
'align info for readability
With Selection
.HorizontalAlignment = xlGeneral
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
' Closes userform when "ok" is selected
Unload Me
'Captures information and changes data from rows to columns
Range("A1:IT1").Select
Selection.Copy
Range("A15").Select
Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
True, Transpose:=True
'Review lines 15 to Last Row and delete if empty
Dim Lastrow As Integer
Lastrow = Range("A" & Rows.Count).End(xlUp).Row
Range("A15:A" & Lastrow).SpecialCells(xlCellTypeBlanks).EntireRow.Delete
Selection.CurrentRegion.Select
Selection.CheckSpelling
Selection.Copy
End Sub