Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi Patrick Molloy sorry for reply after 1 week.
Thanks for the reply it's working nicely but i have one problem it copys same data again when i run the prog. 2nd time. Is there any way it should not copy same data again if i run again. code is here.... Option Explicit Sub PopulateData() ' assume input file has a worksheet called Data Dim ws As Worksheet Set ws = Worksheets("data") Dim rw As Long ' index for reading data Dim targetrow As Long ' row for writing data Dim wsTarget As Worksheet ' where data is to go Dim Col As Long ' used for setting pmt or rct column rw = 2 'assumes first row is heading Do Until ws.Cells(rw, 1).Value = "" If InStr(UCase(Cells(rw, 2).Value), "REC") 0 Then Col = 4 Else Col = 1 End If Set wsTarget = safeSheet(Format$(ws.Cells(rw, 1).Value, "dd-mmmm")) targetrow = wsTarget.Cells(56000, Col).End(xlUp).Row + 1 With wsTarget With .Range(.Cells(targetrow, Col), .Cells(targetrow, Col + 2)) .Value = ws.Range(ws.Cells(rw, 2), ws.Cells(rw, 4)).Value End With End With rw = rw + 1 Loop End Sub Private Function safeSheet(sSheetName As String) As Worksheet On Error Resume Next Set safeSheet = Worksheets(sSheetName) If Err.Number < 0 Then Err.Clear Set safeSheet = ThisWorkbook.Worksheets.Add safeSheet.Name = sSheetName If Err.Number < 0 Then GoTo trap End If On Error GoTo 0 Exit Function trap: MsgBox Err.Description, , "Error Adding Worksheet:" & sSheetName On Error GoTo 0 End Function Thanks Regards Tiya Shah |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
fao patrick molloy | Excel Programming | |||
Patrick- do you still have the file | Excel Programming | |||
Patrick -- 424 Combo Box User Form | Excel Programming | |||
Reply to Tom | Excel Programming | |||
Reply to Tom | Excel Programming |