Copy a specific cell value to column if adjacent column contains data

bunny1122

New Member
Joined
Jul 8, 2022
Messages
21
Office Version
  1. 365
Platform
  1. Windows
Hi All

I have a macro that will extract data from other workbooks and append it to another excel everyday based on the date I input in cell B1.

A sample data below: The data range that is appended daily is column B:K. Then, I have to manually copy the cell(report date) in B1 and paste to Column A accordingly. I need a macro to automate this part, appreciate any inputs. Thank you!

Note: The rows of the data range is not fixed.
1657680462157.png
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Some thing like this:
VBA Code:
With Range("A3").CurrentRegion.Columns(1).SpecialCells(xlCellTypeBlanks)
    .Value = Range("B1")
    .NumberFormat = "dd/mm/yy"
End With
 
Upvote 0
Some thing like this:
VBA Code:
With Range("A3").CurrentRegion.Columns(1).SpecialCells(xlCellTypeBlanks)
    .Value = Range("B1")
    .NumberFormat = "dd/mm/yy"
End With
Thank you! This works on my sample data. I've come across an issue however.

On my actual file, my header ("report date") starts from row 6, when I run the code, the date will populate correctly onto the excel under "Report Date", but the date will also appear row row 4 and 5. I tried this on my sample data without issue though. How can I fix that?

Screenshot of results after running the code
1657690613486.png


Below is the code I'm using to run.
VBA Code:
'Update Reporting Date

    With Range("A6").CurrentRegion.Columns(1).SpecialCells(xlCellTypeBlanks)
    .Value = ThisWorkbook.Sheets("Source").Range("B1")
    .NumberFormat = "dd-Mmm"
End With
 
Upvote 0
Maybe:
VBA Code:
Dim cell As Range
For Each cell In Range("A6").CurrentRegion.Columns(1).SpecialCells(xlCellTypeBlanks)
    With cell
        If .Row > 6 Then
            .Value = Range("B1")
            .NumberFormat = "dd-Mmm"
        End If
    End With
Next
 
Upvote 0
Or, with no loop, code speed may better:
VBA Code:
With Range("A7:A" & Cells(Rows.Count, "B").End(xlUp).Row).SpecialCells(xlCellTypeBlanks)
    .Value = Range("B1")
    .NumberFormat = "dd-Mmm"
End With
 
Upvote 0
Solution
Or, with no loop, code speed may better:
VBA Code:
With Range("A7:A" & Cells(Rows.Count, "B").End(xlUp).Row).SpecialCells(xlCellTypeBlanks)
    .Value = Range("B1")
    .NumberFormat = "dd-Mmm"
End With
Thank you so much! Works like a charm
 
Upvote 0

Forum statistics

Threads
1,215,693
Messages
6,126,242
Members
449,304
Latest member
hagia_sofia

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top