# macro to move row up and down



## wizmaster (Dec 15, 2022)

I'm using this macro to help me move a row of data in excel up one row.   When i use autofilter and have columns hidden, it is not moving the hidden columns - just the columns that is not hidden.  however when i do not have any autofilter, it is moving the full row (including the hidden rows).  Any ideas on how to fix this?   I wonder if the Activecell.row is the right logic to use here?



```
sub upwards

Dim tmp As Long


tmp = 5000
If ActiveCell.Row <> Rows.Count And ActiveCell.Row > 2 Then
    Cells(ActiveCell.Row + 1, 1).EntireRow.Copy Cells(tmp, 1)
    ActiveCell.EntireRow.Copy Cells(ActiveCell.Row + 1, 1)
    Cells(tmp, 1).EntireRow.Copy Cells(ActiveCell.Row, 1)
    ActiveCell.Offset(1, 0).EntireRow.Select
End If
End Sub
```

End Sub


----------



## wizmaster (Dec 15, 2022)

one other thing, the rows are added in a table.  do i need to use another function?


----------



## Peter_SSs (Dec 16, 2022)

Duplicate to: Excel Table, move rows up

In future, please do not post the same question multiple times. Per Forum Rules (#12), posts of a duplicate nature will be locked or deleted.

In relation to your question here, I have closed this thread so please continue in the linked thread.


----------

