Hi,
I am pretty new to VBA and am struggling in writing a simple code.
I'm trying to write a code that locates columns with the headings 'Platform' , 'Complex' , 'Field' and 'Area' and then copy the entire column (Columns may be in different cells and different lengths each time), into a newly created worksheet. And then add two new columns titles called 'TPL' and 'OPAL'.
This is what I have so far, it copies one column but i cannot get it to copy the others:
Any help would be much appreciated.
I am pretty new to VBA and am struggling in writing a simple code.
I'm trying to write a code that locates columns with the headings 'Platform' , 'Complex' , 'Field' and 'Area' and then copy the entire column (Columns may be in different cells and different lengths each time), into a newly created worksheet. And then add two new columns titles called 'TPL' and 'OPAL'.
This is what I have so far, it copies one column but i cannot get it to copy the others:
Code:
Sub Copy_Column()
Dim rng As Range
Dim cl As Object
Dim strMatch As String
strMatch = "Platform"
Set rng = Range("A1:ZZ1")
For Each cl In rng
If cl.Value = strMatch Then
cl.EntireColumn.Copy
Sheets.Add After:=Sheets(Sheets.Count)
ActiveSheet.Paste
Exit For
End If
Next cl
End Sub
Last edited by a moderator: