Hi, I am trying to fill up the blank cells accordingly to the value in above cell, but how do I find the last columns in the worksheet that no header in every column (this is the report generated by system). Currently I am setting the last column as column "Z" but instead it is not the last column, the last column may vary due to the hierarchy level might different which means the total number of column might different as well. The below is my screenshot of the raw file and also my coding. Thanks in advance.
VBA Code:
Option Explicit
Public wbmacrobook As Workbook
Public wbrawfile As Workbook
Public vfile As Variant
Sub GFL()
Dim lr As Long
'Set Macro file
Set wbmacrobook = ThisWorkbook
'Open raw file
vfile = Application.GetOpenFilename("Excel File (*.xlsx;*csv;*xls)," & "*.xlsm*" & "*.csv*" & "*.xls*", 1, "Select Excel File", "Open", False)
'If Cancel then Exit
If TypeName(vfile) = "Boolean" Then
Application.ScreenUpdating = True
'Application.DisplayStatusBar = True
Application.Calculation = xlCalculationAutomatic
Application.EnableEvents = True
Application.DisplayAlerts = True
Application.AskToUpdateLinks = True
Exit Sub
Else
Set wbrawfile = Workbooks.Open(vfile)
Application.AskToUpdateLinks = False
End If
Application.DisplayAlerts = False
'Copy Raw File
wbrawfile.Activate
Range("A:Z").Copy
wbmacrobook.Activate
Sheets("GFL").Range("A:Z").PasteSpecial Paste:=xlPasteValues
'clear selection and close raw file
wbrawfile.Activate
Selection.Clear
wbrawfile.Close savechanges:=False
wbmacrobook.Activate
Application.ScreenUpdating = False
With Sheets("GFL")
lr = .Columns("B:Z").Find(What:="*", SearchDirection:=xlPrevious, SearchOrder:=xlByRows).Row
On Error Resume Next
With .Range("B7:Z" & lr)
.SpecialCells(xlCellTypeBlanks).Formula = "=R[-1]C"
.Value = .Value
End With
Err.Clear
End With
Application.ScreenUpdating = True
End Sub