Copy data from one column to a new column in the same sheet.

InnaG

New Member
Joined
Mar 18, 2019
Messages
19
Hello,
I am working on a macro to find column names "Prov_Specialty" , add new column named "Specialty1" and copy data from the original column to the new column.

Here is how far did I get:

Dim Found As Range
Dim LR As Long
Set Found = Rows(1).Find(what:="Prov_Specialty", LookIn:=xlValues, lookat:=xlWhole)
If Found Is Nothing Then Exit Sub
LR = Cells(Rows.Count, Found.Column).End(xlUp).Row
Found.Offset(, 1).EntireColumn.Insert
Cells(1, Found.Column + 1).Value = "Specialty1"



Do not know how to copy data from Prov_specialty to Speciality1 columns. Please help.
Thank you
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
32,315
Office Version
365
Platform
Windows
Hi & welcome to MrExcel.
How about
Code:
Sub InnaG()
   Dim Found As Range
   Set Found = Rows(1).Find(what:="Prov_Specialty", lookIn:=xlValues, lookat:=xlWhole)
   If Found Is Nothing Then Exit Sub
   Found.EntireColumn.Copy
   Found.Offset(, 1).EntireColumn.Insert
   Found.Offset(, 1).Value = "Specialty1"
End Sub
 

mumps

Well-known Member
Joined
Apr 11, 2012
Messages
8,518
Try:
Code:
Sub CopyCol()
    Application.ScreenUpdating = False
    Dim LastRow As Long, Found As Range
    LastRow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    Set Found = Rows(1).Find(what:="Prov_Specialty", LookIn:=xlValues, lookat:=xlWhole)
    If Not Found Is Nothing Then
        Found.Offset(, 1).EntireColumn.Insert
        Cells(1, Found.Column + 1).Value = "Specialty1"
        Range(Cells(2, Found.Column), Cells(LastRow, Found.Column)).Copy Cells(2, Found.Column + 1)
    End If
    Application.ScreenUpdating = True
End Sub
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
32,315
Office Version
365
Platform
Windows
Not sure which of us you are replying to, but glad we could help & thanks for the feedback
 

Forum statistics

Threads
1,082,261
Messages
5,364,106
Members
400,779
Latest member
lumers

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top