Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
Altri Linguaggi - il Range A2:F2 si inverte con A3:F3
Forum - Altri Linguaggi - il Range A2:F2 si inverte con A3:F3

Avatar
trittico69 (Normal User)
Pro


Messaggi: 144
Iscritto: 02/04/2010

Segnala al moderatore
Postato alle 22:25
Lunedì, 07/03/2011
Non capisco perchè alla fine della macro il Range A2:F2 si inverte con A3:F3….Il cambiamento avviene in questa riga di codice, quando seleziona Range("A3:F" & d).Select
Selection.Sort Key1:=Range("A3"), Order1:=xlAscending
Chi mi aiuta?


Codice sorgente - presumibilmente VB.NET

  1. Sub sta1()
  2. Dim r As Long
  3. Dim r1 As Long
  4. Dim st As String
  5. Dim cp As Long
  6. Dim d As Long
  7. Dim ind As Variant
  8. Dim rr As Long
  9.  
  10.  
  11. 'ELIMINA GLI ENTRATI E GLI USCITI CHE VENGONO RINOMINATI PERCHE' IL NOME SBAGLIATO E FINISCE A FINE 7
  12. Dim G As Range, KK As Range, cl3 As Object, cl4 As Object, _
  13. xx As Long, yy As Long, z As Long, x As Long, _
  14. y As Long, zz As Long
  15. Set G = Range("G3:G1500")
  16. Set KK = Range("K3:K1500")
  17. 'mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm
  18.  
  19. 'AMMETTENDO CHE LA RIGA 1 è OCCUPATA DALLE INTESTAZIONI DI COLONNA
  20. 'EFFETTUO UN CICLO PER TROVARE LA PRIMA CELLA OCCUPATA DELLA COLONNA G;
  21. 'IN OGNI CASO PUOI MODIFICARE IL RANGE G e K EDITANDO LE VARIABILI SOPRA (Set)
  22. For Each cl3 In G
  23. If cl3 = "" Then
  24.     cl3.Select
  25.     x = Selection.Row
  26.     Exit For
  27.     'If cl3 <> "" Then
  28.     Else
  29.         cl3.Select
  30.         x = Selection.Row
  31. 'x è IL NUMERO RIGA DELLA PRIMA CELLA OCCUPATA DELLA COLONNA G
  32.         Exit For
  33.     End If
  34. Next
  35. If cl3 = "" Then
  36.     y = Cells(65536, 7).End(xlUp).Row + 1
  37.     Else
  38.         y = Cells(65536, 7).End(xlUp).Row
  39. End If
  40. 'y è IL NUMERO RIGA DELL'ULTIMA CELLA OCCUPATA DELLA COLONNA G
  41.  
  42. 'mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm
  43.  
  44. 'EFFETTUO UN CICLO PER TROVARE LA PRIMA CELLA OCCUPATA DELLA COLONNA K
  45. For Each cl4 In KK
  46. If cl4 = "" Then
  47.     cl4.Select
  48.     xx = Selection.Row
  49.     Exit For
  50.     'If cl4 <> "" Then
  51.     Else
  52.         cl4.Select
  53.         xx = Selection.Row
  54. 'xx è IL NUMERO RIGA DELLA PRIMA CELLA OCCUPATA DELLA COLONNA K
  55.         Exit For
  56.     End If
  57. Next
  58. If cl4 = "" Then
  59.     yy = Cells(65536, 11).End(xlUp).Row + 1
  60.     Else
  61.         yy = Cells(65536, 11).End(xlUp).Row
  62. End If
  63. 'yy è IL NUMERO RIGA DELL'ULTIMA CELLA OCCUPATA DELLA COLONNA K
  64.  
  65. 'mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm
  66.  
  67. 'DOPPIO CICLO FOR/NEXT PER CONTROLLARE OGNI RIGA OCCUPATA DELLE
  68. 'COLONNE G-H-I-J CON OGNI RIGA OCCUPATA DELLE COLONNE K-L-M-N
  69.  
  70. For z = x To y
  71.     For zz = xx To yy
  72.         If Cells(z, 9) = Cells(zz, 13) And Cells(z, 10) = Cells(zz, 14) _
  73.         And Cells(z, 7) = Cells(zz, 11) Or Cells(z, 8) = Cells(zz, 12) Then
  74.             Range(Cells(z, 7), Cells(z, 10)).ClearContents
  75.             Range(Cells(zz, 11), Cells(zz, 14)).ClearContents
  76.         End If
  77.     Next zz
  78. Next z
  79.  'FINE 7
  80.  
  81.  
  82. Dim cl, cl2, RNG, RNG2, NOME, COGNOME ' CANCELLA I CAMBIAMENTI DI CELLA DEL CCL TR1 TR2 F D IL CODICE FINISCE DOV'è SCRITTO FINE2
  83. r = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
  84. Dim Condizioni As New Collection
  85. Condizioni.Add "F|F"
  86. Condizioni.Add "D|D"
  87. Condizioni.Add "TR1|TR1"
  88. Condizioni.Add "TR2|TR2"
  89. Condizioni.Add "OSS.|OSS."
  90. Condizioni.Add "I.S.|I.S."
  91. Condizioni.Add "EXD.|EXD."
  92. Condizioni.Add "DEG.|DEG."
  93. Condizioni.Add "DEG.|OSS."
  94. Condizioni.Add "DEG.|EXD."
  95. Condizioni.Add "DEG.|I.S."
  96. Condizioni.Add "OSS.|EXD."
  97. Condizioni.Add "OSS.|I.S."
  98. Condizioni.Add "OSS.|DEG."
  99. Condizioni.Add "EXD.|DEG."
  100. Condizioni.Add "EXD.|OSS."
  101. Condizioni.Add "EXD.|I.S."
  102. Condizioni.Add "I.S.|EXD."
  103. Condizioni.Add "I.S.|OSS."
  104. Condizioni.Add "I.S.|DEG."
  105. ReDim c(r) As Integer
  106. Dim i, j, K, cond
  107. Set RNG2 = Range("C3:E" & r)
  108. For Each cl2 In RNG2
  109.     For Each cond In Condizioni
  110.         If cl2.Offset(0, 0) = Split(cond, "|")(0) And cl2.Offset(0, 2) = Split(cond, "|")(1) Then
  111.         i = i + 1
  112.         c(i) = cl2.Row
  113.      End If
  114.     Next
  115. Next
  116. K = i
  117. Sheets("ARCHIVIO").Select
  118. For i = 1 To K
  119.    ActiveSheet.Range("A1:F1").Offset(c(i) - 1, 0).Delete
  120. For j = i + 1 To K
  121.     c(j) = c(j) - 1
  122.    Next
  123. Next 'FINE2
  124.  
  125.  
  126. rr = Range("I" & Rows.Count).End(xlUp).Row 'cancella nella colonna entrati il femminile tr1 e tr2 il codice finisce a fine 5
  127.     For x = 3 To rr
  128.         If Cells(x, "I") = "F" Or Cells(x, "I") = "TR1" Or Cells(x, "I") = "TR2" Then
  129.             Range("G" & x & ":" & "J" & x).ClearContents
  130.         End If
  131.     Next x 'fine 5
  132.  
  133. Range("A3:F" & r).Select 'ordina alfabetico colonna movimenti
  134.     Selection.Sort Key1:=Range("E3"), Order1:=xlAscending, Header:=xlGuess, _
  135.         OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
  136.         DataOption1:=xlSortNormal
  137. Range("G3:J170").Select 'ordina alfabetico colonna entrati
  138.     Selection.Sort Key1:=Range("G3"), Order1:=xlAscending, Header:=xlGuess, _
  139.         OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
  140.         DataOption1:=xlSortNormal
  141. Range("K3:N34").Select ' ordina alfabetico colonna usciti
  142.     Selection.Sort Key1:=Range("K3"), Order1:=xlAscending, Header:=xlGuess, _
  143.         OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
  144.         DataOption1:=xlSortNormal
  145.     Range("G8").Select
  146. Set sh1 = Worksheets("Archivio")
  147. sh1.Activate
  148. Application.ScreenUpdating = False
  149. st = Cells(2, 16)
  150. cp = Cells(2, 17)
  151. Cells(1, 18) = Cells(Rows.Count, 5).End(xlUp).Row
  152. r1 = Cells(1, 18)
  153. Cells(1, 19) = Cells(Rows.Count, 7).End(xlUp).Row
  154. Cells(1, 20) = Cells(Rows.Count, 11).End(xlUp).Row
  155. Cells(2, 18).Select
  156. ActiveCell.FormulaR1C1 = "=LARGE(R[-1]C:R[-1]C[2],1)"
  157. r = Cells(2, 18)
  158. Range(Cells(1, 18), Cells(2, 20)).ClearContents
  159. If r1 < r Then
  160.   If r1 = 2 Then
  161.     Range(Cells(r1 + 1, 1), Cells(r, 4)).Select
  162.     Selection.Insert shift:=xlDown
  163.     Cells(4, 5).Copy
  164.     Range(Cells(r1 + 1, 1), Cells(r, 4)).Select
  165.     ActiveSheet.Paste
  166.     Application.CutCopyMode = False
  167.   Else
  168.     Range(Cells(r1 + 1, 1), Cells(r, 4)).Select
  169.     Selection.Insert shift:=xlDown
  170.   End If
  171. End If
  172. If r1 < r Then d = r Else d = r1
  173. Range("A3:F" & d).Select
  174. Selection.Sort Key1:=Range("A3"), Order1:=xlAscending
  175. For x = 3 To d Step 2
  176.   Range(Cells(x, 1), Cells(x, 14)).Interior.ColorIndex = 45 ' colora di arancione un rigo si e uno no
  177. Next x
  178. Range("A3:N" & r).Select 'seleziona l'area di stampa'
  179. ind = Range("A3:N" & r).Address
  180. ActiveSheet.PageSetup.PrintArea = ind
  181. With ActiveSheet.PageSetup
  182.   .PrintTitleRows = "$1:$2"
  183.   .PrintTitleColumns = ""
  184. End With
  185. With ActiveSheet.PageSetup
  186.   .LeftHeader = "Stampato in Data &D - &T   Pagine &P/&N" 'stampa data ora e numero di pagine'
  187.   .CenterHeader = "" & Chr(10) & "" & Chr(10) & "" & Chr(10) & "" & Chr(10) & "" & Chr(10) & _
  188.     "&""Arial,Grassetto Corsivo""&18Direzione N.C.P. Solliciano - Firenze&""Arial,Normale""&10" & Chr(10) & _
  189. "&""Arial,Grassetto Corsivo""&12Variazioni Celle, Nuovi Arrivi, Uscite, in Data &D" 'intestazione pagina'
  190.   .LeftMargin = Application.InchesToPoints(0.1) 'margine sinistro della stampa'
  191.   .RightMargin = Application.InchesToPoints(0.1) 'margine destro'
  192.   .TopMargin = Application.InchesToPoints(1.6) 'margine alto'
  193.   .BottomMargin = Application.InchesToPoints(0.25) 'adatta lo scritto alla pagina della stampa'
  194.   .HeaderMargin = Application.InchesToPoints(0.1) 'abbassa o alza il titolo della pagina di stampa'
  195.   .FooterMargin = Application.InchesToPoints(0.2) 'abbassa o alza lo scritto sotto la pagine'
  196.   .PrintHeadings = False
  197.   .PrintGridlines = False
  198.   .PrintComments = xlPrintNoComments
  199.   .CenterHorizontally = False
  200.   .CenterVertically = False
  201.   .Orientation = xlLandscape 'stampa in verticale...per stampare in orizzontale sostituisci con =x1portrait'
  202.   .Draft = False
  203.   .PaperSize = xlPaperA4 'tipo di foglio usati per la stampa'
  204.   .FirstPageNumber = xlAutomatic
  205.   .Order = xlDownThenOver
  206.   .BlackAndWhite = False
  207.   .Zoom = 100 'ingrandisce o rimpiccolisce la stampa'
  208.   .PrintErrors = xlPrintErrorsDisplayed
  209. End With
  210. Application.ScreenUpdating = True
  211. If st = "V" Then ActiveWindow.SelectedSheets.PrintPreview
  212. If st = "S" Then ActiveWindow.SelectedSheets.PrintOut Copies:=cp
  213. If r1 < r Then
  214. Range(Cells(r1 + 1, 1), Cells(r, 4)).Select
  215.   Selection.Delete shift:=xlUp
  216. End If
  217. Cells(2, 1).Select
  218. End Sub


PM Quote