detweiler
Board Regular
- Joined
- Aug 2, 2013
- Messages
- 62
As a follow up to the copy cell value to different worksheet with loop post, thanks to @rainbow7766 for getting the initial ask out there and @jolivanes for providing an efficient working solution, which was:
Again, credit where credit is due, the code was supplied by @jolivanes.
While I did get it to work, I do have two questions.
VBA Code:
Sub Maybe_So()
Dim dataArr
Dim lr As Long, lc As Long, i As Long, curSh
Dim shT As Worksheet, shM As Worksheet
Application.ScreenUpdating = False
Set shM = Worksheets("Master")
Set shT = Worksheets("Template")
curSh = ActiveSheet.Name
lr = shM.Cells(Rows.Count, 1).End(xlUp).Row
lc = shM.Cells.Find("*", , , , xlByColumns, xlPrevious).Column
dataArr = shM.Cells(1).Resize(lr, lc).Value
For i = 1 To lr
shT.Copy After:=Sheets(Sheets.Count)
With Sheets(Sheets.Count)
.Name = "Template " & i
.Cells(2, 2).Value = dataArr(i, 1)
.Cells(2, 4).Value = dataArr(i, 2)
End With
Next i
Sheets(curSh).Activate
Application.ScreenUpdating = True
End Sub
While I did get it to work, I do have two questions.
- My data has a header row and would like to know how to get the macro to start on the second row to pull the values into the new worksheet?
- How do I get the macro to recognize there is no next row of data so that it doesn't create an empty worksheet?