0

I currently have a userform which outputs data into a sheet. I have recently added a table in the output region where my formulas that analyze the data are located, and made it 1000 rows high so that I have space. Now, annoyingly, the data is outputting at the very bottom of the table, not in the first row (I think Excel is interpreting the presence of the table as being a full row and then going below it). I tried just deleting the intervening empty rows, and that works as long as the first row is never deleted. Unfortunately, this will be a form which is cleared and re-filled each day, so I'd rather not require the user to keep the top row at all times.

My current code is the below - how do I change it to ask it to output into the first row of Table2 instead of the first available row of Sheet1?

Private Sub Adddatabutton_Click()

Dim iRow As Long

Dim ws As Worksheet

Set ws = Worksheets("Sheet1")

iRow = ws.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row

' A bunch of output code

' A bunch of code that clears the form

End Sub
7
  • The first cell of the table is the .DataBodyRange.Cells(1, 1).
    – BigBen
    Jul 9, 2020 at 17:22
  • If you need to find the first available row in a table, see this.
    – BigBen
    Jul 9, 2020 at 17:23
  • @BigBen Sorry, I'm new to this. Where would I put the .DataBodyRange.Cells(1,1) in the code above? Would it go in as iRow = ws.DataBodyRange.Cells(1,1).End(x1Up).Offset(1,0).Row ? Jul 11, 2020 at 17:44
  • Can you share a bit more of your code, specifically the output code?
    – BigBen
    Jul 11, 2020 at 18:56
  • @BigBen Sure! It just goes ws.Cells(iRow, 1) = Me.Textbox1.Value ws.Cells(iRow, 2) = Me.textbox2.Value ws.Cells(iRow, 3) = Me.checkbox1 ws.Cells(iRow, 4) = Me.checkbox2 and then at the end I clear the data using Me.Textbox1.Value = "" Me.textbox2.Value = "" Me.checkbox1 = FALSE Me.checkbox2 = FALSE etc. Jul 13, 2020 at 13:41

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.