VBA - how to fill blanks with the same information in the same column but referencing to another column

Mangosteenlu

New Member
Joined
Jul 5, 2015
Messages
9
Hi All,
I am new to Forum & VBA, just wondering if anyone with good knowledge of VBA can help me with the issue i am facing at work.
We have the massive data downloaded from our system every week, which I need to manipulate the data into the right format. I extracted a few rows from our data set explaining what i need to do on a weekly basis.
In this example, i need to use filter on Column B to select one internal ref each time, then fill blanks in Column A same as the one shown in the same column, but they have to have the same internal ref. In this example, blank cells (A2 to A6) manually fill in as 'RE123' which is same as the cell from A7 to A9 as they have the same internal reference.
Can anyone write a VBA code to perform this task quickly? thank you so much for your help in advance.
1694525734193.png
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Try:
VBA Code:
Sub FillBlanksCells()
    Application.ScreenUpdating = False
    Dim srcRng As Range, v As Variant, i As Long, dic As Object, lRow As Long, fVisRow As Long, lVisRow As Long, fnd As Range
    lRow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    v = Range("B2:B" & lRow)
    Set dic = CreateObject("Scripting.Dictionary")
    For i = LBound(v) To UBound(v)
        If Not dic.exists(v(i, 1)) Then
            dic.Add v(i, 1), Nothing
            Range("A1").CurrentRegion.AutoFilter 2, v(i, 1)
            Set srcRng = Range("A2:A" & lRow).SpecialCells(xlVisible)
            fVisRow = Rows("2:" & lRow).SpecialCells(xlCellTypeVisible).Row
            lVisRow = Cells(Rows.Count, "B").End(xlUp).Row
            Set fnd = srcRng.Find(what:="*", after:=Cells(fVisRow, 1), LookIn:=xlValues)
            srcRng = fnd
        End If
    Next i
    Range("A1").AutoFilter
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Hi Mumps,

Wow,you are brilliant, it works. Thanks very much for taking time to help me.
when i copy your VBA code to the real data, I have changed column A to N, and B to R, but it did not work. I think there must be something else needs be amended. Sorry, is it possible for you to help me once more time? I am really appreciate your help. thanks


1694531413117.png
 
Upvote 0
Try:
VBA Code:
Sub FillBlanksCells()
    Application.ScreenUpdating = False
    Dim srcRng As Range, v As Variant, i As Long, dic As Object, lRow As Long, fVisRow As Long, lVisRow As Long, fnd As Range
    lRow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    v = Range("R2:R" & lRow)
    Set dic = CreateObject("Scripting.Dictionary")
    For i = LBound(v) To UBound(v)
        If Not dic.exists(v(i, 1)) Then
            dic.Add v(i, 1), Nothing
            Range("A1").CurrentRegion.AutoFilter 18, v(i, 1)
            Set srcRng = Range("N2:N" & lRow).SpecialCells(xlVisible)
            fVisRow = Rows("2:" & lRow).SpecialCells(xlCellTypeVisible).Row
            lVisRow = Cells(Rows.Count, "R").End(xlUp).Row
            Set fnd = srcRng.Find(what:="*", after:=Cells(fVisRow, 14), LookIn:=xlValues)
            srcRng = fnd
        End If
    Next i
    Range("A1").AutoFilter
    Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,094
Messages
6,123,071
Members
449,092
Latest member
ipruravindra

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