Visual basic invertire le righe

Esempi di codice

0
0

visual basic invertire le righe

'===============================================================================
'>> FlipRows()
'===============================================================================
' Flips the order of cells vertically (NB: formulas will be converted to values)
'===============================================================================
Sub FlipRows()
    Debug.Print "Running FlipRows Sub"
        
    '*********************************
    ' VALIDATIONS and declarations
    '*********************************
    '(DECLARATIONS)
    Dim wbInit As Workbook: Set wbInit = ActiveWorkbook
    Dim wsInit As Worksheet: Set wsInit = ActiveSheet
    Dim rInit As Range: Set rInit = Selection
    Dim s_rInit As String: s_rInit = Selection.Address
    Dim sErrMsg As String
    
    Dim ArrInit() As Variant
    Dim ArrNew() As Variant
    Dim iRowCnt As Integer
    Dim iColumnCnt As Integer
    Dim x As Integer
    Dim y As Integer
    
    '---------------------------------
    '               WORK
    '---------------------------------
    '1) Get number of rows
    '2) Make array of initial row values
    '3) Make array of initial new (flipped) row values
    '4) Enter values of new (flipped) row values
    
    'Z) Reactivate the initial workbook/worksheet
        
    '--(1)
    iRowCnt = Selection.Rows.Count
    iColumnCnt = Selection.Columns.Count
    
    '--(2)
    ReDim ArrInit(1 To iColumnCnt, 1 To iRowCnt)
    
    For y = 1 To iRowCnt
        For x = 1 To iColumnCnt
            
            ArrInit(x, y) = rInit.Item(y, x).Value
            Debug.Print "[x: " & x & "][y: " & y & "][rInit: " & ArrInit(x, y) & "]"
        
        Next x
    Next y
    
    '--(3)
    ReDim ArrNew(1 To iColumnCnt, 1 To iRowCnt)
    
    For y = 1 To iRowCnt
        For x = 1 To iColumnCnt
    
            ArrNew(x, y) = ArrInit(x, iRowCnt - y + 1)
            Debug.Print "[x: " & x & "][y: " & y & "][ArrNew: " & ArrInit(x, iRowCnt - y + 1) & "]"
        
        Next x
    Next y
    
    '--(4)
    For y = 1 To iRowCnt
        For x = 1 To iColumnCnt
            
            Debug.Print "[x: " & x & "][y: " & y & "][ArrNew: " & ArrNew(x, y) & "]"
            rInit.Item(y, x).Value = ArrNew(x, y)
        
        Next x
    Next y
    
    '--(Z)
    wbInit.Activate
    wsInit.Activate
    Range(s_rInit).Select
End Sub

Pagine correlate

Pagine di esempio simili

In altre lingue

Questa pagina è in altre lingue

Русский
..................................................................................................................
English
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................
Балгарскі
..................................................................................................................
Íslensk
..................................................................................................................