Excel - Macro required please

Asked By Dr Hackenbush
09-Feb-10 05:11 AM
This is a repost as I dont think I made much sense previously. !

Here is a graphic of what I would like to get

http://tinypic.com/r/21jx9gm/6

Doesnt need to delete anything just copy and sort from Sheet1 to Sheet2,
and each time its run add the new records it finds above or below whats
already there.

Thanks for looking and hopefully helping me out !
Worksheets
(1)
DestCell.Offset
(1)
Macro
(1)
Rows.Count
(1)
TargetRng
(1)
PerWill
(1)
HThanks
(1)
PerIt
(1)
  Per Jessen replied to Dr Hackenbush
09-Feb-10 07:13 AM
Hi

Not sure how to determine which entries are new, so the macro just copy all
entries marked with "y" each time the macro run.

Try this one:

Sub AAA()
Dim ShA As Worksheet
Dim ShB As Worksheet
Dim DestCell As Range
Dim TargetRng As Range

Application.ScreenUpdating = False
Set ShA = Worksheets("Sheet1")
Set ShB = Worksheets("Sheet2")
Set DestCell = ShB.Range("B2")
'Set DestCell = ShB.Range("A" & Rows.Count).End(xlUp).Offset(1, 0)
Set TargetRng = ShA.Range("F2", ShA.Range("F" & Rows.Count).End(xlUp))

For Each cell In TargetRng
If cell.Value = "y" Then
ShA.Range("A" & cell.Row).Resize(1, 2).Copy DestCell
If cell.Offset(0, 2) = "ch" Then
DestCell.Offset(0, 2) = cell.Offset(0, 1)
Else
DestCell.Offset(0, 3) = cell.Offset(0, 1)
End If
Set DestCell = DestCell.Offset(1, 0)
End If
Next
Application.ScreenUpdating = True
End Sub

Regards,
Per
  Dr Hackenbush replied to Per Jessen
09-Feb-10 08:39 AM
Hi Per

It works perfectly, I had to make one small change which I think was just a
typing error, Set DestCell = ShB.Range("B2") changed B2 to A2,

On Sheet1  "y"  will only be new entries as after processing they change to

Thanks very much for your time Its really appreciated

all the best
Dr H
  Per Jessen replied to Dr Hackenbush
10-Feb-10 03:00 AM
Hi Dr H

Thanks for your reply.

Good you solved my typo error. As only new entries are marked with 'y', you
have to use my second Set DestCell=... statement which is currently
commented out to write new data to first empty line. The statement 'Set
DestCell = ShB.Range("B2") ' can be deleted or commented out.

Best regards,
Per
  Dr Hackenbush replied to Per Jessen
10-Feb-10 04:29 AM
Per
Will do , thanks for the advice

once again thanks for your time and help
Dr H
Create New Account
help
Sheets("feuil3").Columns(1).Clear Sheets("feuil3").[a1] = "Copie sans doublon" derlg = Sheets("feuil1").Cells(Rows.Count, "A").End(3).Row Sheets("feuil1").Range("A2:A" & derlg).Copy Sheets("feuil3").[a2] derlg = Sheets("Feuil2").Cells(Rows.Count, "A").End(3).Row derlgFeuil3 = Sheets("feuil3").Cells(Rows Count, "A").End(3).Row + 1 Sheets("feuil2").Range("A2:A" & derlg).Copy Sheets("feuil3").Range Cells.Clear Application.ScreenUpdating = False calc = Application.Calculation Application.Calculation = xlCalculationManual '* * derlg = Sheets("feuil1").Cells(Rows.Count, "A").End(3).Row Sheets("feuil1").Range("A1:d" & derlg).Copy Sheets("feuil3").[a1] derlg
Workbook Dim wks As Worksheet Set wkb = 3D Workbooks("code_row_v2.xls") Set wks = 3D wkb.Worksheets("Sheet1") Dim trouve As Boolean Dim LigCol1 As Integer 'num = E9ro de ligne pour la is messing in the secondary loop block code. Thanks, Cyberuser Excel Programming Discussions WorksheetFunction (1) Worksheets (1) Workbooks (1) Sheets (1) Error (1) Excel (1) Describe (1) AVERAGE (1) I tried http: / / www.eternal-september.org ClassicVB Users Regroup! comp.lang.basic.visual.misc [. . . . ] The following macro avoids Insert Shift: = 3DxlDown, which can be very inefficient. I assume that there is no Application.EnableEvents = 3D False '* * if you wish, delete #if and #endif lines Workbooks("code_row_v2.xls").Worksheets("Sheet1").Active '* * ra and rb are first nonblank data to last '* * contiguous nonblank data in is the appropriate Insert Shift: = 3DxlDown operations. Let me know if you want that. This macro appears to do what you asked for. . . Sub AlignColumnData() Dim M As Long, D As Long, Main As Variant, Data As Variant With WorksheetFunction Main = .Transpose(Range("A1:A" & Cells(Rows.Count, "A").End(xlUp).Row)) Data = .Transpose(Range("B1:B" & Cells(Rows.Count, "B").End(xlUp).Row)) End With Range("A:B").Clear M = LBound(Main) D
Business Objects \ CHR \ Export of SGUK.xls") Set ws = wb2.Sheets("Sheet1") lngRow = ws.Cells(Rows.Count, "A").End(xlUp).Row wb1.Sheets("EAM405").Range("A8:T27").Copy ws.Range("A" & lngRow Excel Miscellaneous Discussions Excel 2003 (1) Sheets (1) Application.DisplayAlerts (1) Worksheet (1) Workbook (1) Rows.Count (1) XlPasteValues (1) VbYesNo (1) Hi, Try this Private Sub CommandButton1_Click() Sub Button2_Click() Dim wb1 Business Objects \ CHR \ Export of SGUK.xls ") Set ws = wb2.Sheets("Sheet1") lngRow = ws.Cells(Rows.Count, "A").End(xlUp).Row wb1.Sheets("EAM405").Range("A8:T27").Copy ws.Range("A" & lngRow sheets i need to copy: However it is throwing an error for lngRow = ws.Cells(Rows.Count, data it copies to the external sheet its starting on row 1, i need it
Macro change - help please Excel Hi I have the following macro that if it finds a "y" in a cell in a sheet called "current" it row onto another sheet called "paid" Can somebody let me know how to change the macro so that as well as copying data to "paid" sheet it will also then change the cells with "y" on data being written if the macro is run multiple times Many thanks if you can help. here is the Macro Sub paid() Sheets("Current").Select Dim ShA As Worksheet Dim ShB As Worksheet Dim DestCell As Range Dim TargetRng As Range Application.ScreenUpdating = False Set ShA = Worksheets("Current") Set ShB = Worksheets("Paid") 'Set DestCell = ShB.Range("A2") Set DestCell = ShB.Range("A" & Rows.Count).End(xlUp
resulted to an error and will ask if the user want to continue running the macro or not. Below is one of my basic filter and delete routine (got it here one criteria Set rng = ActiveSheet.AutoFilter.Range Set rng = rng.Offset(1, 0).Resize(rng.Rows.Count - 1) Set rng = rng.Columns(1).SpecialCells(xlVisible).EntireRow rng.Delete ActiveSheet.AutoFilterMode = False 'deactivate Excel Programming Discussions AutoFilter (1) Sheets (1) Error (1) Worksheet (1) Workbook (1) Routine (1) Macro (1) Application (1) This should do it: Sub tester3() Dim FilterRng As Range Dim rng 3D120 'creteria is filter range) Set rng = 3D ActiveSheet.AutoFilter.Range If rng.SpecialCells(xlVisible).Rows.Count > 1 Then Set rng = 3D rng.Offset(1, 0).Resize(rng.Rows.Count - 1) Set rng = 3D rng.Columns(1).SpecialCells(xlVisible).EntireRow rng.Delete End If ActiveSheet