Dark tyranus
New Member
- Joined
- Feb 19, 2020
- Messages
- 1
- Office Version
- 2016
- Platform
- MacOS
Hi guys,
I need help with my VBA, there is my problem :
We have a rather large file that exports lot of columns of data. We want to use VBA to copy some of the columns to another sheet with the same name than the column. The columns are scattered through out the entire workbook. I have the code created to copy the entire column to the new sheet. Problem is :
- I would like to rename the new sheet created with an automatic name by taking the name manually (filled inside the VBA).
- I need to filter the column "Status Code" with only results in "200" and copy after the different column (e.g : filter by Status Code in 200 -> copy URL column and Title column -> create new sheet with these informations).
Some of the columns we are trying to copy are : Title, Status Code, Indexability, etc
The code i'm using for now is :
Any suggestions?
I need help with my VBA, there is my problem :
We have a rather large file that exports lot of columns of data. We want to use VBA to copy some of the columns to another sheet with the same name than the column. The columns are scattered through out the entire workbook. I have the code created to copy the entire column to the new sheet. Problem is :
- I would like to rename the new sheet created with an automatic name by taking the name manually (filled inside the VBA).
- I need to filter the column "Status Code" with only results in "200" and copy after the different column (e.g : filter by Status Code in 200 -> copy URL column and Title column -> create new sheet with these informations).
Some of the columns we are trying to copy are : Title, Status Code, Indexability, etc
The code i'm using for now is :
VBA Code:
Sub weasel()
'The sheet with all the imported data columns must be active when this macro is run
Dim newSht As Worksheet, sSht As Worksheet, Hdrs As Variant, i As Long, Fnd As Range
Set sSht = ActiveSheet
'Expand the array below to include all relevant column headers
Hdrs = Array("Address", "Status Code")
Application.ScreenUpdating = False
Set newSht = Worksheets.Add(after:=sSht)
With sSht.UsedRange.Rows(1)
For i = LBound(Hdrs) To UBound(Hdrs)
Set Fnd = .Find(Hdrs(i), lookat:=xlWhole)
If Not Fnd Is Nothing Then
Intersect(Fnd.EntireColumn, sSht.UsedRange).Copy Destination:=newSht.Cells(1, i + 1)
End If
Next i
Application.CutCopyMode = False
End With
Hdrs = Array("Address", "Indexability")
Application.ScreenUpdating = False
Set newSht = Worksheets.Add(after:=sSht)
With sSht.UsedRange.Rows(1)
For i = LBound(Hdrs) To UBound(Hdrs)
Set Fnd = .Find(Hdrs(i), lookat:=xlWhole)
If Not Fnd Is Nothing Then
Intersect(Fnd.EntireColumn, sSht.UsedRange).Copy Destination:=newSht.Cells(1, i + 1)
End If
Next i
Application.CutCopyMode = False
End With
Application.ScreenUpdating = True
End Sub
Any suggestions?