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

InnaG

New Member
Joined
Mar 18, 2019
Messages
22
Office Version
  1. 2016
  2. 2013
Platform
  1. Windows
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
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
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
 
Upvote 0
Solution
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
 
Upvote 0
Not sure which of us you are replying to, but glad we could help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,767
Messages
6,174,390
Members
452,561
Latest member
amir5104

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