I would like to limit the range in selection which only select within column (5) but I don’t know how to fix the code. My purpose is the macro only run if user choose range within column(5) because if they choose the range in other columns, the macro cant run well, otherwise the macro will be stopped or show the message to user that “pls choose in range column(5) only”. Pls help me to solve this problem. Thanks in advance.
Code
Public Sub Update_Data()
Dim cell As Excel.Range
For Each cell In Selection
If (cell.Value = "") Then
GoTo Continue
End If
cell.Offset(, 6).FormulaR1C1 = "=VLOOKUP(RC[-6],'[DAILY IMPORT STATUS 2019.- REVISEDxlsx.xlsx]Sheet1'!C6:C14,7,FALSE)"
cell.Offset(, 6).Value2 = cell.Offset(, 6).Value2
cell.Offset(, 7).FormulaR1C1 = "=VLOOKUP(RC[-7],'[DAILY IMPORT STATUS 2019.- REVISEDxlsx.xlsx]Sheet1'!C6:C14,8,FALSE)"
cell.Offset(, 7).Value2 = cell.Offset(, 7).Value2
cell.Offset(, 8).FormulaR1C1 = "=VLOOKUP(RC[-8],'[DAILY IMPORT STATUS 2019.- REVISEDxlsx.xlsx]Sheet1'!C6:C14,9,FALSE)"
cell.Offset(, 8).Value2 = cell.Offset(, 8).Value2
Continue:
Next cell
End Sub
Display More