Im reaching out to the VBA wizards / masterminds to see if you could help me resolve an issue I have with a section of my code, I have tried merging the two below programs in various ways, but I cant get them to play nice with each other, I would be grateful if someone can help me out.
Objectives
'the Aim is to search Row 1, find header called Purchasing Document, select data to last row, exuding header name
'and name the data range to PurchDoc as in P1 below
'the Two subroutines are from two programs, P1 is mine, P2 is what I sourced from the internet, which I am trying to merge together, but unsuccessful
'It would also be really good if I could clear the name range RNG as if the purchasing document header moves column
'I think it would try to create duplicate name ranges if the original is not cleared. (dont know how to do this) RNG= nothing (maybe??)
P1
'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
'original code that works and is currently in use
'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Dim RNG As Range
Set RNG = Range("O2:O" & last_row)
ThisWorkbook.Names.Add Name:="PurchDoc", RefersTo:=RNG
P2 - test
'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
'sourced Code that works Separately in a test module to find and select all the column
'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Dim Crng As Range
Set Crng = Range("A1:AJ1").Find("Purchasing Document") ' ideally the whole of Row (1:1) Although the data should extend past column AJ anyway
If Crng Is Nothing Then _
MsgBox "Description column was not found." ' dont want this cant remove withought Block if error
Range(Crng, Crng.End(xlDown)).Select
' End If ' if message box enable end if disabled works, other way round, block if error
End Sub
Headers
Thanks for your help in advance.
Many thanks
Dave.
Objectives
'the Aim is to search Row 1, find header called Purchasing Document, select data to last row, exuding header name
'and name the data range to PurchDoc as in P1 below
'the Two subroutines are from two programs, P1 is mine, P2 is what I sourced from the internet, which I am trying to merge together, but unsuccessful
'It would also be really good if I could clear the name range RNG as if the purchasing document header moves column
'I think it would try to create duplicate name ranges if the original is not cleared. (dont know how to do this) RNG= nothing (maybe??)
P1
'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
'original code that works and is currently in use
'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Dim RNG As Range
Set RNG = Range("O2:O" & last_row)
ThisWorkbook.Names.Add Name:="PurchDoc", RefersTo:=RNG
P2 - test
'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
'sourced Code that works Separately in a test module to find and select all the column
'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Dim Crng As Range
Set Crng = Range("A1:AJ1").Find("Purchasing Document") ' ideally the whole of Row (1:1) Although the data should extend past column AJ anyway
If Crng Is Nothing Then _
MsgBox "Description column was not found." ' dont want this cant remove withought Block if error
Range(Crng, Crng.End(xlDown)).Select
' End If ' if message box enable end if disabled works, other way round, block if error
End Sub
Headers
Company Code | Creation Date | Baseline Payment Dte | Document Date | Net due date | Terms of Payment | Delivery Date | ID | Document number | Vendor | Vendor Name | Reference | Resubmission WI | Actual Agent | Purchasing Document | GR-Based Inv. Verif. | Goods Receipt | GR Done | Workitem Notes | Requisitioner | Created by | Purchasing Group | Business Area | Plant | Workitem Description | Material | Vendor Type | Pending Days | Pending Network Days | Pending Group | Days Overdue | Group Due Next | Queue | Resub Code | Re-Submittion Rasons | GR PO Line Report |
Thanks for your help in advance.
Many thanks
Dave.