VBA that updates a range as I insert new rows

cameronnicol

New Member
Joined
Dec 1, 2017
Messages
8
Hello,

The below VBA code populates a series of cells in a table, using A2 to update the file path. Column A contains an order number. It will also generate an error message if the fil path specified does not exist.

I would like the range "ordnum" to update as users insert new rows into the table. So if someone put an order number in A3 the file path would update.

Any help would be much appreciated, I'm completely stuck and a bit of a noob.

Cheers.

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("A2")) Is Nothing Then 'check if A2 is the cell that changed
ordnum = Range("A2")
If ordnum = "" Then Exit Sub 'check if order number is blank if so exit sub

'Display error message and change cell colour if folder does not exist.
If Not FileFolderExists("P:\GBBSB\Telecoms\Fixed\NRSWA\Geospatial\01_Products\" & ordnum & "\01_WIP") Then
        MsgBox "Folder does not exist!"
        Range("A2").Interior.Color = RGB(230, 0, 0)
        Exit Sub
Else: Range("A2").Interior.Color = RGB(0, 230, 0)
    End If
    Range("B2").Formula = "='P:\GBBSB\Telecoms\Fixed\NRSWA\Geospatial\01_Products\" & ordnum & "\01_WIP\[" & ordnum & " Production Checklist.xlsx]Order and Response Details'!$B$2" 'Client
    Range("E2").Formula = "='P:\GBBSB\Telecoms\Fixed\NRSWA\Geospatial\01_Products\" & ordnum & "\01_WIP\[" & ordnum & " Production Checklist.xlsx]Order and Response Details'!$B$3" 'Site Size
    Range("H2").Formula = "='P:\GBBSB\Telecoms\Fixed\NRSWA\Geospatial\01_Products\" & ordnum & "\01_WIP\[" & ordnum & " Production Checklist.xlsx]Order and Response Details'!$B$4" 'Turnaround
    Range("I2").Formula = "='P:\GBBSB\Telecoms\Fixed\NRSWA\Geospatial\01_Products\" & ordnum & "\01_WIP\[" & ordnum & " Production Checklist.xlsx]Order and Response Details'!$E$3" 'Ordered date
    Range("J2").Formula = "='P:\GBBSB\Telecoms\Fixed\NRSWA\Geospatial\01_Products\" & ordnum & "\01_WIP\[" & ordnum & " Production Checklist.xlsx]Order and Response Details'!$E$5" 'Due date
    Range("L2").Formula = "='P:\GBBSB\Telecoms\Fixed\NRSWA\Geospatial\01_Products\" & ordnum & "\01_WIP\[" & ordnum & " Production Checklist.xlsx]Time Spent'!$AK$10" 'Completed by
    Range("P2").Formula = "='P:\GBBSB\Telecoms\Fixed\NRSWA\Geospatial\01_Products\" & ordnum & "\01_WIP\[" & ordnum & " Production Checklist.xlsx]Order and Response Details'!$B$5" 'Estimated drawing hours
    Range("S2").Formula = "='P:\GBBSB\Telecoms\Fixed\NRSWA\Geospatial\01_Products\" & ordnum & "\01_WIP\[" & ordnum & " Production Checklist.xlsx]Time Spent'!$AW$11" 'GDC time
    Range("T2").Formula = "='P:\GBBSB\Telecoms\Fixed\NRSWA\Geospatial\01_Products\" & ordnum & "\01_WIP\[" & ordnum & " Production Checklist.xlsx]Time Spent'!$AW$12" 'UK time
End If
End Sub
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.

Forum statistics

Threads
1,223,900
Messages
6,175,276
Members
452,629
Latest member
SahilPolekar

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