10. januar 2014 - 14:59Der er
4 kommentarer og 1 løsning
Kopi af data
Sub CopyFilter_A() Dim r, r2, d As Range Dim n As Long Dim cYear, cStatus, cPage, cPrice, cSeasonType Dim tStatus As String cYear = 2 cStatus = 13 cPage = 3 cPrice = 11 cSeasonType = 12 tStatus = "Fortsat i 2014"
On Error Resume Next With ActiveSheet.AutoFilter.Range Set r2 = .Offset(1, 0).Resize(.Rows.Count - 1, 1).SpecialCells(xlCellTypeVisible) n = .Columns(1).SpecialCells(xlCellTypeVisible).Count - 1 End With On Error GoTo 0
If r2 Is Nothing Then MsgBox "Ingen husdate data valgt !!!" Else 'MsgBox n Set r = ActiveSheet.AutoFilter.Range Set d = r.Offset(r.Rows.Count, 0).Cells(1, 1) r.Offset(1, 0).Resize(r.Rows.Count - 1).Copy Destination:=d
Ovenstående kode kopierer indhold fra udklipsholder ( ialt 6 linier ) til næste blanke linie i mit regneark ... dette er tilfældet i 9 ud af 10 gange en bruger skal bruge funktionen ... men den 10'ende gang skal der tilfæjes en ekstra linie hvor indholdet er identisk med den indkopierede linie 6, med den undtagelse at den 7´ende linie skal have denne værdi :
d.Offset(6, cSeasonType).Resize(n).Value = "G"
Hvordan ser hele koden ud i en Sub CopyFilter_B() version ???
Sub CopyFilter_A() Dim r, r2, d As Range Dim n As Long Dim cYear, cStatus, cPage, cPrice, cSeasonType Dim tStatus As String Dim RW As Integer, L As Variant, I As Integer 'NY cYear = 2 cStatus = 13 cPage = 3 cPrice = 11 cSeasonType = 12 tStatus = "Fortsat i 2014"
On Error Resume Next With ActiveSheet.AutoFilter.Range Set r2 = .Offset(1, 0).Resize(.Rows.Count - 1, 1).SpecialCells(xlCellTypeVisible) n = .Columns(1).SpecialCells(xlCellTypeVisible).Count - 1 RW = .Rows.Count 'NY End With On Error GoTo 0
If r2 Is Nothing Then MsgBox "Ingen husdate data valgt !!!" Else L = Array("A", "B", "C", "D", "E", "F", "G") 'NY 'MsgBox n Set r = ActiveSheet.AutoFilter.Range Set d = r.Offset(r.Rows.Count, 0).Cells(1, 1) r.Offset(1, 0).Resize(r.Rows.Count - 1).Copy Destination:=d
Sub CopyFilter_A() Dim r, r2, d As Range Dim n As Long Dim cYear, cStatus, cPage, cPrice, cSeasonType Dim tStatus As String Dim RW As Integer, L As Variant, I As Integer 'NY cYear = 2 cStatus = 13 cPage = 3 cPrice = 11 cSeasonType = 12 tStatus = "Fortsat i 2014"
On Error Resume Next With ActiveSheet.AutoFilter.Range Set r2 = .Offset(1, 0).Resize(.Rows.Count - 1, 1).SpecialCells(xlCellTypeVisible) n = .Columns(1).SpecialCells(xlCellTypeVisible).Count - 1
End With On Error GoTo 0
If r2 Is Nothing Then MsgBox "Ingen husdate data valgt !!!" Else L = Array("A", "B", "C", "D", "E", "F", "G") 'NY 'MsgBox n Set r = ActiveSheet.AutoFilter.Range Set d = r.Offset(r.Rows.Count, 0).Cells(1, 1) r.Offset(1, 0).Resize(r.Rows.Count - 1).Copy Destination:=d
Det virker ikke efter hensigten ... koden indsætter blot G seks gange i kolonne 12 ( cSeasonType = 12 ) øvrige celler er blanke og alle seks bliver efterfølgende slettet af denne
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.