Vba: Import Data From Another Worksheet (Paste Value)

muhammad susanto

Well-known Member
Joined
Jan 8, 2013
Messages
2,077
Office Version
  1. 365
  2. 2021
Platform
  1. Windows
hi all.

i found vba code to import data from another , this code below work properly
unfortunally, data that success imported still contains formula .
i want to how to code work with result ..like Paste Value not included formula
VBA Code:
Sub ImportDatafromotherworksheet()
    Dim wkbCrntWorkBook As Workbook
    Dim wkbSourceBook As Workbook
    Dim rngSourceRange As Range
    Dim rngDestination As Range
    Set wkbCrntWorkBook = ActiveWorkbook
    With Application.FileDialog(msoFileDialogOpen)
        .Filters.Clear
        .Filters.Add "Excel 2007-13", "*.xlsx; *.xlsm; *.xls"
        .AllowMultiSelect = False
        .Show
        If .SelectedItems.Count > 0 Then
            Workbooks.Open .SelectedItems(1)
            Set wkbSourceBook = ActiveWorkbook
            Set rngSourceRange = Application.InputBox(prompt:="Select source range", Title:="Source Range", Default:="A1", Type:=8)
            wkbCrntWorkBook.Activate
            Set rngDestination = Application.InputBox(prompt:="Select destination cell", Title:="Select Destination", Default:="A1", Type:=8)
            rngSourceRange.Copy rngDestination
            rngDestination.CurrentRegion.EntireColumn.AutoFit
            wkbSourceBook.Close False
        End If
    End With
End Sub
sorry:
in "destination sheet" i don't use AutoFit Column....
i want to remove auto fit column
someone help me, great appreciated

.sst
 
Last edited:

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
sorry i missing it:
in "destination sheet" i don't use AutoFit Column....
1). i want to remove auto fit column

2) in "destination sheet" show input box "Select destination cell" then i must do select/drag cell needed, how to make more simple...
just type start cell to representative select all range that needed ...e.g. "Type start cell destination.."
 
Upvote 0
Try this for the Paste Values & Remove Autofit.
I don't understand your "2)" above since you don't have to select a destination area, the code only requires your to select the start cell.

VBA Code:
Sub ImportDatafromotherworksheet_Orig()
    Dim wkbCrntWorkBook As Workbook
    Dim wkbSourceBook As Workbook
    Dim rngSourceRange As Range
    Dim rngDestination As Range
    Set wkbCrntWorkBook = ActiveWorkbook
    With Application.FileDialog(msoFileDialogOpen)
        .Filters.Clear
        .Filters.Add "Excel 2007-13", "*.xlsx; *.xlsm; *.xls"
        .AllowMultiSelect = False
        .Show
        If .SelectedItems.Count > 0 Then
            Workbooks.Open .SelectedItems(1)
            Set wkbSourceBook = ActiveWorkbook
            Set rngSourceRange = Application.InputBox(prompt:="Select source range", Title:="Source Range", Default:="A1", Type:=8)
            wkbCrntWorkBook.Activate
            Set rngDestination = Application.InputBox(prompt:="Select destination cell", Title:="Select Destination", Default:="A1", Type:=8)
            
            '----------- Changes made ------------
            ' XXX Change Copy to Copy Paste Special
            ' rngSourceRange.Copy rngDestination
            rngSourceRange.Copy
            rngDestination.PasteSpecial Paste:=xlPasteValues    ' My preference would be to use xlPasteValuesAndNumberFormats
            ' rngDestination.PasteSpecial Paste:=xlPasteFormats ' Uncomment this if you also want the Format (leave the previous as just values)
            
            ' XXX Comment out autofit as requested
            'rngDestination.CurrentRegion.EntireColumn.AutoFit
            '----------- End of Changes made ------------
            
            wkbSourceBook.Close False
        End If
    End With
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,214,653
Messages
6,120,751
Members
448,989
Latest member
mariah3

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