marialewis16
New Member
- Joined
- Sep 22, 2023
- Messages
- 2
- Office Version
- 2019
- Platform
- Windows
Hello,
I got a great little code from someone named BSB a couple of weeks ago on the other excel forum. However, I changed my project a little and need an adjustment to it that I can't seem to figure out.
His code worked perfectly for what I had asked for at the time. Basically I would like to enter a number into a cell and then that number of rows from the bottom of a Table would populate to the top of a Range in different columns. The code here does this well when everything is on one worksheet.
However, I need help separating the parts to different worksheets. I would like the Data Source Table to be on Sheet1, the input cell (where I would type in the number of rows I want) to be on Sheet2 and the Range where the rows are sent to would be on sheet3.
Also, I would like the new Range to actually be a Table and have the empty rows that you get when reducing the number in the input cell to be deleted. Hopefully that can be coded as well.
I appreciate any help you guys can give me, thank you so much!
-Maria
I got a great little code from someone named BSB a couple of weeks ago on the other excel forum. However, I changed my project a little and need an adjustment to it that I can't seem to figure out.
His code worked perfectly for what I had asked for at the time. Basically I would like to enter a number into a cell and then that number of rows from the bottom of a Table would populate to the top of a Range in different columns. The code here does this well when everything is on one worksheet.
However, I need help separating the parts to different worksheets. I would like the Data Source Table to be on Sheet1, the input cell (where I would type in the number of rows I want) to be on Sheet2 and the Range where the rows are sent to would be on sheet3.
Also, I would like the new Range to actually be a Table and have the empty rows that you get when reducing the number in the input cell to be deleted. Hopefully that can be coded as well.
I appreciate any help you guys can give me, thank you so much!
-Maria
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim x As Long
With ThisWorkbook.Sheets("Sheet1")
Application.EnableEvents = False
If Target.Cells.Count = 1 Then
.Range("K2:N" & .Cells(Rows.Count, "K").End(xlUp).Row).ClearContents
x = .Range("I3")
.Range("K2").Resize(x, 4).Value = .ListObjects("Table1").Range(.ListObjects("Table1").ListRows.Count + 1, 1).Offset(-x + 1).Resize(x, 4).Value
End If
Application.EnableEvents = True
End With
End Sub