Avatar of Euro5
Euro5
Flag for United States of America asked on

Excel vba

Hello!
I need to write in VBA
In column B of all sheets in this workbook
Move all data down 1 row.

Can anyone help?
Thank you!!

VBAMicrosoft ExcelMicrosoft Office

Avatar of undefined
Last Comment
Bill Prew

8/22/2022 - Mon
Fabrice Lambert

Maybe something like the following:
Option Explicit

Public Sub test()
    Dim Wb As Excel.Workbook
    Set Wb = ThisWorkbook
   
    Dim Ws As Excel.Worksheet
    For Each Ws In Wb.Worksheets
        MoveData Ws.Columns("B"), 1
    Next
End Sub

Private Sub MoveData(ByRef Column As Excel.Range, ByVal RowOffset As Long)
    Dim Ws As Excel.Worksheet
    Set Ws = Column.Parent
   
    Dim Rng As Excel.Range
    Set Rng = Ws.Range(Column.Cells(1), Column.Cells(Column.Cells.Count).End(xlUp))
    Rng.Copy
    Rng.Offset(RowOffset:=RowOffset).PasteSpecial xlPasteAll

    Column.Cells(1).Clear
End Sub

Open in new window

ASKER CERTIFIED SOLUTION
Bill Prew

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Euro5

ASKER
Hi, Bill! It's just not doing anything...hmm
Euro5

ASKER
Hold on - I think I see my mistake... thanks, Bill!
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
Bill Prew

Welcome, glad that helped, thanks for the feedback.

»bp