Hi, I need help figuring out a code that will do the following:
I am trying to copy a range of cells from sheet 2 to sheet 1 as many times as the number in cell A1 (in Sheet 2) indicates (the number in A1 will change on its own).
I would like to copy range of cells in sheet 2 starting in from cell B3 through the last cell with data (since the length of the range will vary) and paste it in Sheet 1 in column A in the next available blank cell.
Here is an example:
Sheet 2
A1: 3
B3: Cat
B4: Dog
B5: Banana
I would need Range("B3:B5") copied 3 times.
So Sheet 1 would look like the following:
A
Cat
Dog
Banana
Cat
Dog
Banana
Cat
Dog
Banana
I have this so far but it won’t paste all the cells in the range just the first cell of the range:
Sub CopyBasedOnCellValue()
Dim DataEntry As Worksheet, DataSht As Worksheet
Dim ItemName As range, ItemCount As range
Dim NRow As Long, TargetCell As range
With ThisWorkbook
Set DataEntry = .Sheets("Sheet 2")
Set DataSht = .Sheets("Sheet 1")
End With
With DataEntry
Set ItemName = .range("B3:B20")
Set ItemCount = .range("A1")
End With
With DataSht
NRow = .range("A" & Rows.count).End(xlUp).Row + 1
Set TargetCell = .range("A" & NRow)
TargetCell = ItemName.Value
End With
End Sub
Any help is greatly appreciate it!
Thank you so much!
Idalia
I am trying to copy a range of cells from sheet 2 to sheet 1 as many times as the number in cell A1 (in Sheet 2) indicates (the number in A1 will change on its own).
I would like to copy range of cells in sheet 2 starting in from cell B3 through the last cell with data (since the length of the range will vary) and paste it in Sheet 1 in column A in the next available blank cell.
Here is an example:
Sheet 2
A1: 3
B3: Cat
B4: Dog
B5: Banana
I would need Range("B3:B5") copied 3 times.
So Sheet 1 would look like the following:
A
Cat
Dog
Banana
Cat
Dog
Banana
Cat
Dog
Banana
I have this so far but it won’t paste all the cells in the range just the first cell of the range:
Sub CopyBasedOnCellValue()
Dim DataEntry As Worksheet, DataSht As Worksheet
Dim ItemName As range, ItemCount As range
Dim NRow As Long, TargetCell As range
With ThisWorkbook
Set DataEntry = .Sheets("Sheet 2")
Set DataSht = .Sheets("Sheet 1")
End With
With DataEntry
Set ItemName = .range("B3:B20")
Set ItemCount = .range("A1")
End With
With DataSht
NRow = .range("A" & Rows.count).End(xlUp).Row + 1
Set TargetCell = .range("A" & NRow)
TargetCell = ItemName.Value
End With
End Sub
Any help is greatly appreciate it!
Thank you so much!
Idalia