• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Copy column from one sheet to another using inputbox

Dee

Member
Hi Guys,


Below is the code which i am trying to copy column from one sheet to another by using input box.What missing in this is, its copying only from the default opened sheet. I need to give input for sheet also similar to source and destination column via input box or any other way. Can anyone pls help me on this?


Sub SelectEntireColumn()


Dim x As String

Dim y As String

'Dim sheet As Range


On Error Resume Next

source_file = Application.GetOpenFilename(FileFilter:="Excel files (*.xls), *.xls", Title:="Please choose a file")

Set sourcefile = Workbooks.Open(Filename:=source_file, ReadOnly:=yes)

'sheet = InputBox("select sheet")

'Worksheets(sheet).Select


x = InputBox("Select the column to copy")


Cells(1, x).Select


Selection.EntireColumn.Select

Selection.Copy

Worksheets("Sheet2").Activate

y = InputBox("select the column to paste")

Cells(1, y).Select

ActiveSheet.Paste


End Sub


Thanking you in advance,

Dee
 
Using this technique, they would select the source and destination column using the mouse. This allows, indeed requires, navigating to the appropriate sheet.


Sub SelectEntireColumn()


Dim x As Range

Dim y As Range

'Dim sheet As Range


On Error Resume Next

source_file = Application.GetOpenFilename(FileFilter:="Excel files (*.xls), *.xls", Title:="Please choose a file")

Set sourcefile = Workbooks.Open(Filename:=source_file, ReadOnly:=yes)

'sheet = InputBox("select sheet")

'Worksheets(sheet).Select


Set x = Application.InputBox("Select the column to copy using the mouse", Type:=8)

Set y = Application.InputBox("Select the column to paste to using the mouse", Type:=8)


x.EntireColumn.Copy Cells(1, y.Column)


End Sub
 
Hi Xld,


Your code will be perfect if i copy and paste continuous columns(series of column) say from A to E but in my case i will be selecting columns randomly ie., a,C,F,H,K ...

so i though of giving input box to select sheet,source column and destination column.


Thanks,

Dee
 
Back
Top