VBA code to start auto fill in column A until multiple or single data available in column B.

Copper Contributor

Dear Reader,

 

I work on some handful of excels everyday. For some files I need to fill Column A until multiple or single data available in Column B(usually from B2 the datas will be available as B1 could be a header row). and if no data available in a sheet the macro should move for the next file without throwing any error. what would be the code for the same. got failed with multiple codes.

 

Thanks in advance for your assistance.

3 Replies

@Chalz2709 

Are you saying that one or multiple excel files are opened and you want to fill column A based on what is filled in column B?

What is to be filled in column A?

 

Isn't it better if you upload a sample file to show us what exactly you are trying to achieve by mocking up the desired output manually in column A?

Hello Sir,
I want to update on multiple excels. Yes Column A is to be auto filled with A2 Data until the datas in column b is available.

File vairies everyday. sometimes multiple number of rows would be filled. Sometimes single and later sometimes empty sheets.

@Chalz2709 

The following code will loop through all the worksheets of the open workbooks and fill the column A with what is there in cell A2 on those sheets.

 

Sub FillColumnA()
Dim wb As Workbook
Dim ws As Worksheet
Dim lr As Long

Application.ScreenUpdating = False

For Each wb In Application.Workbooks
    For Each ws In wb.Worksheets
        lr = ws.Cells(Rows.Count, "B").End(xlUp).Row
        ws.Range("A2:A" & lr).Value = ws.Range("A2").Value
    Next ws
Next wb
Application.ScreenUpdating = True
End Sub