View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default Change target sheet destination from A2 to M2.

The last 1 in this line:
SourceRow.Copy Destination:=Targetsht.Cells(TargetRow, 1)
is the column number. 1=A, 2=B, ...

So maybe...

SourceRow.Copy Destination:=Targetsht.Cells(TargetRow, 13)

Even nicer is that .cells() will accept either a number or a letter (if it's
valid). So you could use:

SourceRow.Copy Destination:=Targetsht.Cells(TargetRow, "M")











"J.W. Aldridge" wrote:

Code works fine, just need minor adjustment to paste to M2 instead of
A2.

Sub Cop_RowS_To_Sheets_TA()
'copy rows to worksheets based on value in column A
'assume the worksheet name to paste to is the value in Col A
Dim CurrentCell As Range
Dim SourceRow As Range
Dim Targetsht As Worksheet
Dim TargetRow As Long
Dim CurrentCellValue As String

'start with cell A1 on Sheet1
Set CurrentCell = Worksheets("all corrects").Cells(1, 2) 'row 1
column 1

Do While Not IsEmpty(CurrentCell)
CurrentCellValue = CurrentCell.Value
Set SourceRow = CurrentCell.EntireRow

'Check if worksheet exists
On Error Resume Next
Testwksht = Worksheets(CurrentCellValue).Name
If Err.Number = 0 Then
'MsgBox CurrentCellValue & " worksheet Exists"
Else
'TO INSERT SHEETS BEFORE A SPECIFIED SHEET, CHANGE NAME BELOW
(END)
Worksheets.Add(befo=Sheets("TA_END")).Name =
CurrentCellValue
End If

On Error GoTo 0 'reset on error to trap errors again

Set Targetsht = ActiveWorkbook.Worksheets(CurrentCellValue)
'note: using CurrentCell.value gave me an error if the value was
numeric

' Find next blank row in Targetsht - check using Column A
TargetRow = Targetsht.Cells(Rows.Count, 1).End(xlUp).Row + 1
SourceRow.Copy Destination:=Targetsht.Cells(TargetRow, 1)

'do the next cell
Set CurrentCell = CurrentCell.Offset(1, 0)
Loop
End Sub


--

Dave Peterson