Hi,
I am very new at VBA. However, I'm working on this tool, where I need to develop the following in sequence:
1. User has to browse for a particular workbook
2. User then selects the sheet required for copying
3. User then selects a rage of columns required to be copied
4. This tool copies column D, along with the range, and pastes it in Sheet 2 in the Active Worbook
The code is as follows, but it doesn't compile successfully.
Any help will be appreciated!
I am very new at VBA. However, I'm working on this tool, where I need to develop the following in sequence:
1. User has to browse for a particular workbook
2. User then selects the sheet required for copying
3. User then selects a rage of columns required to be copied
4. This tool copies column D, along with the range, and pastes it in Sheet 2 in the Active Worbook
The code is as follows, but it doesn't compile successfully.
Code:
Sub ImportData()
Dim wkbCrntWorkBook As Workbook
Dim wkbSourceBook As Workbook
Dim rngSourceRange, rngSourceRange2 As Range
Dim rngDestination, rngDestination2 As Range
Set wkbCrntWorkBook = ActiveWorkbook
With Application.FileDialog(msoFileDialogOpen)
.Filters.Clear
.Filters.Add "Excel 2002-03", "*.xls", 1
.Filters.Add "Excel 2007", "*.xlsx; *.xlsm; *.xlsa", 2
.AllowMultiSelect = False
.Show
If .SelectedItems.Count > 0 Then
Workbooks.Open .SelectedItems(1)
Set wkbSourceBook = ActiveWorkbook
[COLOR=#ff0000]'code to select sheet from the workbook[/COLOR]
Set rngSourceRange = Application.InputBox(prompt:="Select source range", Title:="Source Range", Default:="A1", Type:=8)
Set rngSourceRange2 = wkbSourceBook.ActiveSheet.Cells(2, 4) ' required to select column D completely
wkbCrntWorkBook.Activate
Set rngDestination = ActiveSheet.Cells(2, 2) [COLOR=#ff0000] ' paste destination must be column B onwards, i.e, whatever the user selects as range[/COLOR]
Set rngDestination2 = ActiveSheet.Cells(1, 1) [COLOR=#ff0000] ' paste destination must be column A, i.e, from D of other sheet to A of this sheet[/COLOR]
rngSourceRange.copy rngDestination
rngSourceRange2.copy rngDestination2
rngDestination.CurrentRegion.EntireColumn.AutoFit
wkbSourceBook.Close False
End If
End With
End Sub
Private Sub Import_Click()
ImportData
End Sub
Any help will be appreciated!
Last edited: