VBA kijelölt cellák tartalmának törlése
2020-02-26T09:18:06+01:00
2020-02-26T10:00:23+01:00
2022-08-11T18:25:29+02:00
A.Ortega
Sziasztok!



Az alábbi makrót szeretném futtatni (kijelölt cellák tartalmát törölné), de nem töröl ki semmit és nem is ír ki hibát. Mi lehet a probléma?

Sub Makró2() ' ' Makró2 Makró ' ' Range("D6:E60").Select ActiveWindow.SmallScroll Down:=-36 Range("D6:E60,G6:H60").Select Range("G6").Activate ActiveWindow.SmallScroll Down:=-27 Range("D6:E60,G6:H60,J6:K60").Select Range("J6").Activate ActiveWindow.SmallScroll Down:=-33 Range("D6:E60,G6:H60,J6:K60,M6:N60").Select Range("M6").Activate ActiveWindow.SmallScroll Down:=-27 Range("D6:E60,G6:H60,J6:K60,M6:N60,P6:Q60").Select Range("P6").Activate ActiveWindow.SmallScroll Down:=-51 Range("D6:E60,G6:H60,J6:K60,M6:N60,P6:Q60,S6:T60").Select Range("S6").Activate ActiveWindow.SmallScroll Down:=-51 Range("D6:E60,G6:H60,J6:K60,M6:N60,P6:Q60,S6:T60,V6:W60").Select Range("V6").Activate ActiveWindow.SmallScroll Down:=-45 Range("D6:E60,G6:H60,J6:K60,M6:N60,P6:Q60,S6:T60,V6:W60,Y6:Z60").Select Range("Y6").Activate ActiveWindow.SmallScroll Down:=-39 Range("D6:E60,G6:H60,J6:K60,M6:N60,P6:Q60,S6:T60,V6:W60,Y6:Z60,AB6:AC60"). _ Select Range("AB6").Activate ActiveWindow.SmallScroll Down:=-48 Range( _ "D6:E60,G6:H60,J6:K60,M6:N60,P6:Q60,S6:T60,V6:W60,Y6:Z60,AB6:AC60,AE6:AF60"). _ Select Range("AE6").Activate ActiveWindow.SmallScroll Down:=-51 Range( _ "D6:E60,G6:H60,J6:K60,M6:N60,P6:Q60,S6:T60,V6:W60,Y6:Z60,AB6:AC60,AE6:AF60,AH6:AI60" _ ).Select Range("AH6").Activate ActiveWindow.SmallScroll Down:=-51 Range( _ "D6:E60,G6:H60,J6:K60,M6:N60,P6:Q60,S6:T60,V6:W60,Y6:Z60,AB6:AC60,AE6:AF60,AH6:AI60,AK6:AL60" _ ).Select Range("AK6").Activate ActiveWindow.SmallScroll Down:=-39 Range( _ "D6:E60,G6:H60,J6:K60,M6:N60,P6:Q60,S6:T60,V6:W60,Y6:Z60,AB6:AC60,AE6:AF60,AH6:AI60,AK6:AL60,AN6:AO60" _ ).Select Range("AN6").Activate ActiveWindow.SmallScroll Down:=-45 Range( _ "D6:E60,G6:H60,J6:K60,M6:N60,P6:Q60,S6:T60,V6:W60,Y6:Z60,AB6:AC60,AE6:AF60,AH6:AI60,AK6:AL60,AN6:AO60,AQ6:AR60" _ ).Select Range("AQ6").Activate ActiveWindow.ScrollColumn = 6 ActiveWindow.ScrollColumn = 10 ActiveWindow.ScrollColumn = 14 ActiveWindow.ScrollColumn = 15 ActiveWindow.ScrollColumn = 16 ActiveWindow.ScrollColumn = 17 ActiveWindow.ScrollColumn = 19 ActiveWindow.ScrollColumn = 20 ActiveWindow.ScrollColumn = 21 ActiveWindow.ScrollColumn = 22 ActiveWindow.ScrollColumn = 23 ActiveWindow.ScrollColumn = 24 ActiveWindow.ScrollColumn = 25 ActiveWindow.ScrollColumn = 26 ActiveWindow.ScrollColumn = 27 ActiveWindow.ScrollColumn = 28 ActiveWindow.ScrollColumn = 29 ActiveWindow.ScrollColumn = 30 ActiveWindow.ScrollColumn = 31 ActiveWindow.ScrollColumn = 35 ActiveWindow.ScrollColumn = 37 ActiveWindow.ScrollColumn = 39 ActiveWindow.ScrollColumn = 41 ActiveWindow.ScrollColumn = 42 ActiveWindow.ScrollColumn = 43 ActiveWindow.ScrollColumn = 44 ActiveWindow.ScrollColumn = 45 ActiveWindow.ScrollColumn = 46 ActiveWindow.ScrollColumn = 45 ActiveWindow.ScrollColumn = 44 ActiveWindow.ScrollColumn = 43 ActiveWindow.ScrollColumn = 42 ActiveWindow.ScrollColumn = 43 ActiveWindow.SmallScroll Down:=-36 Range( _ "D6:E60,G6:H60,J6:K60,M6:N60,P6:Q60,S6:T60,V6:W60,Y6:Z60,AB6:AC60,AE6:AF60,AH6:AI60,AK6:AL60,AN6:AO60,AQ6:AR60,AT6:AU60" _ ).Select Range("AT6").Activate ActiveWindow.SmallScroll Down:=-39 Range( _ "D6:E60,G6:H60,J6:K60,M6:N60,P6:Q60,S6:T60,V6:W60,Y6:Z60,AB6:AC60,AE6:AF60,AH6:AI60,AK6:AL60,AN6:AO60,AQ6:AR60,AT6:AU60,AW6:AX60" _ ).Select Range("AW6").Activate ActiveWindow.SmallScroll Down:=-42 Range( _ "D6:E60,G6:H60,J6:K60,M6:N60,P6:Q60,S6:T60,V6:W60,Y6:Z60,AB6:AC60,AE6:AF60,AH6:AI60,AK6:AL60,AN6:AO60,AQ6:AR60,AT6:AU60,AW6:AX60,AZ6:BA60" _ ).Select Range("AZ6").Activate ActiveWindow.SmallScroll Down:=-36 Range( _ "D6:E60,G6:H60,J6:K60,M6:N60,P6:Q60,S6:T60,V6:W60,Y6:Z60,AB6:AC60,AE6:AF60,AH6:AI60,AK6:AL60,AN6:AO60,AQ6:AR60,AT6:AU60,AW6:AX60,AZ6:BA60,BC6:BD60" _ ).Select Range("BC6").Activate ActiveWindow.SmallScroll Down:=-48 Range( _ "D6:E60,G6:H60,J6:K60,M6:N60,P6:Q60,S6:T60,V6:W60,Y6:Z60,AB6:AC60,AE6:AF60,AH6:AI60,AK6:AL60,AN6:AO60,AQ6:AR60,AT6:AU60,AW6:AX60,AZ6:BA60,BC6:BD60,BF6:BG60" _ ).Select Range("BF6").Activate ActiveWindow.SmallScroll Down:=-33 Range( _ "D6:E60,G6:H60,J6:K60,M6:N60,P6:Q60,S6:T60,V6:W60,Y6:Z60,AB6:AC60,AE6:AF60,AH6:AI60,AK6:AL60,AN6:AO60,AQ6:AR60,AT6:AU60,AW6:AX60,AZ6:BA60,BC6:BD60,BF6:BG60,BI6:BJ60" _ ).Select Range("BI6").Activate ActiveWindow.SmallScroll Down:=-33 Range( _ "D6:E60,G6:H60,J6:K60,M6:N60,P6:Q60,S6:T60,V6:W60,Y6:Z60,AB6:AC60,AE6:AF60,AH6:AI60,AK6:AL60,AN6:AO60,AQ6:AR60,AT6:AU60,AW6:AX60,AZ6:BA60,BC6:BD60,BF6:BG60,BI6:BJ60,BL6:BM60" _ ).Select Range("BL6").Activate ActiveWindow.SmallScroll Down:=-33 Range( _ "D6:E60,G6:H60,J6:K60,M6:N60,P6:Q60,S6:T60,V6:W60,Y6:Z60,AB6:AC60,AE6:AF60,AH6:AI60,AK6:AL60,AN6:AO60,AQ6:AR60,AT6:AU60,AW6:AX60,AZ6:BA60,BC6:BD60,BF6:BG60,BI6:BJ60,BL6:BM60,BO6:BP60" _ ).Select Range("BO6").Activate ActiveWindow.SmallScroll Down:=-33 Range( _ "D6:E60,G6:H60,J6:K60,M6:N60,P6:Q60,S6:T60,V6:W60,Y6:Z60,AB6:AC60,AE6:AF60,AH6:AI60,AK6:AL60,AN6:AO60,AQ6:AR60,AT6:AU60,AW6:AX60,AZ6:BA60,BC6:BD60,BF6:BG60,BI6:BJ60,BL6:BM60,BO6:BP60,BR6:BS60" _ ).Select Range("BR6").Activate ActiveWindow.SmallScroll Down:=-36 Range( _ "D6:E60,G6:H60,J6:K60,M6:N60,P6:Q60,S6:T60,V6:W60,Y6:Z60,AB6:AC60,AE6:AF60,AH6:AI60,AK6:AL60,AN6:AO60,AQ6:AR60,AT6:AU60,AW6:AX60,AZ6:BA60,BC6:BD60,BF6:BG60,BI6:BJ60,BL6:BM60,BO6:BP60,BR6:BS60,BU6:BV60" _ ).Select Range("BU6").Activate ActiveWindow.SmallScroll Down:=-30 Range( _ "D6:E60,G6:H60,J6:K60,M6:N60,P6:Q60,S6:T60,V6:W60,Y6:Z60,AB6:AC60,AE6:AF60,AH6:AI60,AK6:AL60,AN6:AO60,AQ6:AR60,AT6:AU60,AW6:AX60,AZ6:BA60,BC6:BD60,BF6:BG60,BI6:BJ60,BL6:BM60,BO6:BP60,BR6:BS60,BU6:BV60,BX6:BY60" _ ).Select Range("BX6").Activate ActiveWindow.SmallScroll Down:=-39 Range( _ "D6:E60,G6:H60,J6:K60,M6:N60,P6:Q60,S6:T60,V6:W60,Y6:Z60,AB6:AC60,AE6:AF60,AH6:AI60,AK6:AL60,AN6:AO60,AQ6:AR60,AT6:AU60,AW6:AX60,AZ6:BA60,BC6:BD60,BF6:BG60,BI6:BJ60,BL6:BM60,BO6:BP60,BR6:BS60,BU6:BV60,BX6:BY60,CA6:CB60" _ ).Select Range("CA6").Activate ActiveWindow.SmallScroll Down:=-33 Range( _ "D6:E60,G6:H60,J6:K60,M6:N60,P6:Q60,S6:T60,V6:W60,Y6:Z60,AB6:AC60,AE6:AF60,AH6:AI60,AK6:AL60,AN6:AO60,AQ6:AR60,AT6:AU60,AW6:AX60,AZ6:BA60,BC6:BD60,BF6:BG60,BI6:BJ60,BL6:BM60,BO6:BP60,BR6:BS60,BU6:BV60,BX6:BY60,CA6:CB60,CD6:CE60" _ ).Select Range("CD6").Activate ActiveWindow.ScrollColumn = 42 ActiveWindow.ScrollColumn = 43 ActiveWindow.ScrollColumn = 44 ActiveWindow.ScrollColumn = 45 ActiveWindow.ScrollColumn = 46 ActiveWindow.ScrollColumn = 48 ActiveWindow.ScrollColumn = 49 ActiveWindow.ScrollColumn = 50 ActiveWindow.ScrollColumn = 51 ActiveWindow.ScrollColumn = 54 ActiveWindow.ScrollColumn = 55 ActiveWindow.ScrollColumn = 56 ActiveWindow.ScrollColumn = 57 ActiveWindow.ScrollColumn = 58 ActiveWindow.ScrollColumn = 59 ActiveWindow.ScrollColumn = 61 ActiveWindow.ScrollColumn = 62 ActiveWindow.ScrollColumn = 63 ActiveWindow.ScrollColumn = 64 ActiveWindow.ScrollColumn = 65 ActiveWindow.ScrollColumn = 66 ActiveWindow.ScrollColumn = 67 ActiveWindow.ScrollColumn = 68 ActiveWindow.SmallScroll Down:=-54 Range( _ "D6:E60,G6:H60,J6:K60,M6:N60,P6:Q60,S6:T60,V6:W60,Y6:Z60,AB6:AC60,AE6:AF60,AH6:AI60,AK6:AL60,AN6:AO60,AQ6:AR60,AT6:AU60,AW6:AX60,AZ6:BA60,BC6:BD60,BF6:BG60,BI6:BJ60,BL6:BM60,BO6:BP60,BR6:BS60,BU6:BV60,BX6:BY60,CA6:CB60,CD6:CE60,CG6:CH60" _ ).Select Range("CG6").Activate ActiveWindow.SmallScroll Down:=-30 Range( _ "D6:E60,G6:H60,J6:K60,M6:N60,P6:Q60,S6:T60,V6:W60,Y6:Z60,AB6:AC60,AE6:AF60,AH6:AI60,AK6:AL60,AN6:AO60,AQ6:AR60,AT6:AU60,AW6:AX60,AZ6:BA60,BC6:BD60,BF6:BG60,BI6:BJ60,BL6:BM60,BO6:BP60,BR6:BS60,BU6:BV60,BX6:BY60,CA6:CB60,CD6:CE60,CG6:CH60,CJ6:CK60" _ ).Select Range("CJ6").Activate ActiveWindow.SmallScroll Down:=-42 Range( _ "D6:E60,G6:H60,J6:K60,M6:N60,P6:Q60,S6:T60,V6:W60,Y6:Z60,AB6:AC60,AE6:AF60,AH6:AI60,AK6:AL60,AN6:AO60,AQ6:AR60,AT6:AU60,AW6:AX60,AZ6:BA60,BC6:BD60,BF6:BG60,BI6:BJ60,BL6:BM60,BO6:BP60,BR6:BS60,BU6:BV60,BX6:BY60,CA6:CB60,CD6:CE60,CG6:CH60,CJ6:CK60,CM6:CN60" _ ).Select Range("CM6").Activate ActiveWindow.SmallScroll Down:=-39 Range( _ "D6:E60,G6:H60,J6:K60,M6:N60,P6:Q60,S6:T60,V6:W60,Y6:Z60,AB6:AC60,AE6:AF60,AH6:AI60,AK6:AL60,AN6:AO60,AQ6:AR60,AT6:AU60,AW6:AX60,AZ6:BA60,BC6:BD60,BF6:BG60,BI6:BJ60,BL6:BM60,BO6:BP60,BR6:BS60,BU6:BV60,BX6:BY60,CA6:CB60,CD6:CE60,CG6:CH60,CJ6:CK60,CM6:CN60" _ ).Select Range("CP6").Activate Selection.ClearContents ActiveWindow.SmallScroll Down:=-51 ActiveWindow.ScrollColumn = 67 ActiveWindow.ScrollColumn = 66 ActiveWindow.ScrollColumn = 62 ActiveWindow.ScrollColumn = 50 ActiveWindow.ScrollColumn = 35 ActiveWindow.ScrollColumn = 19 ActiveWindow.ScrollColumn = 4 Range("B2").Select End Sub
Sokkal jobb lenne egy egyszerűbb kód. Igazából ezekből a tartományokból kéne a törlés:

"D6:E60,G6:H60,J6:K60,M6:N60,P6:Q60,S6:T60,V6:W60,Y6:Z60,AB6:AC60,AE6:AF60,AH6:AI60,AK6:AL60,AN6:AO60,AQ6:AR60,AT6:AU60,AW6:AX60,AZ6:BA60,BC6:BD60,BF6:BG60,BI6:BJ60,BL6:BM60,BO6:BP60,BR6:BS60,BU6:BV60,BX6:BY60,CA6:CB60,CD6:CE60,CG6:CH60,CJ6:CK60,CM6:CN60,CP6:CQ60"


Előre is köszönöm a segítséget!
Mutasd a teljes hozzászólást!
Szedd szét:

 Range("D6:E60,G6:H60,J6:K60,M6:N60,P6:Q60,S6:T60,V6:W60,Y6:Z60").Select
     Application.CutCopyMode = False
     Selection.ClearContents

Range("AB6:AC60,AE6:AF60,AH6:AI60,AK6:AL60,AN6:AO60,AQ6:AR60,AT6:AU60").Select
     Application.CutCopyMode = False
     Selection.ClearContents


Range("AW6:AX60,AZ6:BA60,BC6:BD60,BF6:BG60,BI6:BJ60,BL6:BM60,BO6:BP60").Select
     Application.CutCopyMode = False
     Selection.ClearContents


Range("BR6:BS60,BU6:BV60,BX6:BY60,CA6:CB60,CD6:CE60,CG6:CH60,CJ6:CK60,CM6:CN60,CP6:CQ60").Select
     Application.CutCopyMode = False
     Selection.ClearContents
Mutasd a teljes hozzászólást!

  • Range("D6:E60,G6:H60,J6:K60,M6:N60,P6:Q60,S6:T60,V6:W60,Y6:Z60,AB6:AC60,AE6:AF60,AH6:AI60,AK6:AL60,AN6:AO60,AQ6:AR60,AT6:AU60,AW6:AX60,AZ6:BA60,BC6:BD60,BF6:BG60,BI6:BJ60,BL6:BM60,BO6:BP60,BR6:BS60,BU6:BV60,BX6:BY60,CA6:CB60,CD6:CE60,CG6:CH60,CJ6:CK60,CM6:CN60,CP6:CQ60"Select
        Range("CQ60").Activate
        Application.CutCopyMode = False
        Selection.ClearContents
    Mutasd a teljes hozzászólást!
  • "Run-time error '1004':

    Method 'Range' of object'_Global' failed.

     hibát ír ki. A Debug után pedig a tartományokat jelöli ki.
    Mutasd a teljes hozzászólást!
  • Szedd szét:

     Range("D6:E60,G6:H60,J6:K60,M6:N60,P6:Q60,S6:T60,V6:W60,Y6:Z60").Select
         Application.CutCopyMode = False
         Selection.ClearContents

    Range("AB6:AC60,AE6:AF60,AH6:AI60,AK6:AL60,AN6:AO60,AQ6:AR60,AT6:AU60").Select
         Application.CutCopyMode = False
         Selection.ClearContents


    Range("AW6:AX60,AZ6:BA60,BC6:BD60,BF6:BG60,BI6:BJ60,BL6:BM60,BO6:BP60").Select
         Application.CutCopyMode = False
         Selection.ClearContents


    Range("BR6:BS60,BU6:BV60,BX6:BY60,CA6:CB60,CD6:CE60,CG6:CH60,CJ6:CK60,CM6:CN60,CP6:CQ60").Select
         Application.CutCopyMode = False
         Selection.ClearContents
    Mutasd a teljes hozzászólást!
Tetszett amit olvastál? Szeretnél a jövőben is értesülni a hasonló érdekességekről?
abcd