Lil Stinker
Board Regular
- Joined
- Feb 16, 2022
- Messages
- 151
- Office Version
- 2019
- Platform
- Windows
I'm new to VBA so please forgive me if this is something completely basic. I currently have a worksheet set up where I want to add notes to the sheet via a userform entry. The notes are entered to the sheet row after row, one note/row at a time. What I am trying to have it do is enter the first note in B2, then B3, then B4, so on and so on until it reaches B10. At that point, I want it to redirect to the next open column and start at K2, K3, etc. down to K10. Then if K10 is not empty, change the next available row to B20, down to B30. Once B30 is filled, change again back to K20.
The reason for this is the worksheet is designed a certain way. Row B1 has a header that is Centered Across Selection. Rows A11 through A18 also have other fields that shouldn't be overwritten while B19 has another header Centered Across Selection.
I know how to the get the last row available with the code noteROW = Sheet1.Range("B11").End(xlUp).Row + 1 however, when I change noteROW to equal Sheet1.Range("K11").End(xlUp).Row + 1, it doesn't recognize the header in B1:S1 and places the note in K1 instead of K2. And for reasons unknown to me, when K10 is not empty and I change noteROW to Sheet1.Range("B31").End(xlUp).Row + 1, the notes don't even show up.
Here is the code I've tried working with:
Attached is a screenshot of the worksheet layout which displays the desired results, not the results I've been getting.
I'm sure there are much more sophisticated ways of coding this method. I'm pretty much limited to If/Else statements right now so I'd appreciate any advice!
The reason for this is the worksheet is designed a certain way. Row B1 has a header that is Centered Across Selection. Rows A11 through A18 also have other fields that shouldn't be overwritten while B19 has another header Centered Across Selection.
I know how to the get the last row available with the code noteROW = Sheet1.Range("B11").End(xlUp).Row + 1 however, when I change noteROW to equal Sheet1.Range("K11").End(xlUp).Row + 1, it doesn't recognize the header in B1:S1 and places the note in K1 instead of K2. And for reasons unknown to me, when K10 is not empty and I change noteROW to Sheet1.Range("B31").End(xlUp).Row + 1, the notes don't even show up.
Here is the code I've tried working with:
VBA Code:
Private Sub formsaveBTTN_Click()
Dim noteROW As Long
If scanBOX.Value <> "" And notesBOX.Value <> "" Then
With RTNreceipt
noteROW = .Range("B11").End(xlUp).Row + 1 'first avail row
.Range("B" & noteROW).Value = scanBOX.Value & " - " & notesBOX.Value 'insert barcode and equip notes
If .Range("B10").Value <> Empty Then
noteROW = .Range("K11").End(xlUp).Row + 1 'first avail row in next column
.Range("K" & noteROW).Value = scanBOX.Value & " - " & notesBOX.Value 'insert barcode and equip notes
End If
If .Range("B10").Value <> Empty And .Range("K10").Value <> Empty Then
noteROW = .Range("B31").End(xlUp) + 1 'first avail row on pg2 of notes
.Range("B" & noteROW).Value = scanBOX.Value & " - " & notesBOX.Value 'insert barcode and equip notes
End If
If .Range("B30").Value <> Empty Then
noteROW = .Range("K31").End(xlUp).Row + 1 'first avail row in next column
.Range("K" & noteROW).Value = scanBOX.Value & " - " & notesBOX.Value 'insert barcode and equip notes
End If
If .Range("K30").Value <> Empty Then
MsgBox "****! How much more damage could there be???", vbExclamation, "Out of room!"
End If
End If
Attached is a screenshot of the worksheet layout which displays the desired results, not the results I've been getting.
I'm sure there are much more sophisticated ways of coding this method. I'm pretty much limited to If/Else statements right now so I'd appreciate any advice!