VBA Copy & Paste values & Formats between workbooks

Rollnation

New Member
Joined
Jan 17, 2017
Messages
17
'My code is running through without error all the way to Msgbox.
However the values are cleared from "WbRevDash" workbook and new values are not pasted in. The ranges are just blank.

Any suggestions are helpful! i think it has to do with this part of the code but im a rookie and rely on the pro's around here.

Thanks to all who help around here!



'Now, transfer values from ebRevForecast to wbRevRash:
wbRevDash.Sheets("Data").Range("A8:AS64").Value = wbRevForecast.Sheets("FinalExport").Range("A8:AS64")
wbRevDash.Sheets("Data").Range("CH8:DZ64").Value = wbRevForecast.Sheets("FinalExport").Range("AU8:AS64")




Code:
Option Explicit


Sub FinalExport()


    Dim directory As String
    Dim curDirectory As String
    Dim fileName As Variant
    Dim wbRevForecast As Workbook
    Dim wbRevDash As Workbook
   
    Set wbRevForecast = ThisWorkbook
    
'******************************************SETTINGS***********************************************************
    
    directory = "K:\CODE 150\COST\RevForecastTool"
    fileName = Dir(directory & "*.xl??")
    
'*************************************************************************************************************
    
    'Changes drive and directory
    ChDrive directory
    ChDir directory
    
    'Open filepath,selected Revenue Dashboard
    fileName = Application.GetOpenFilename(MultiSelect:=False)
    
    'if user cancels
    'If fileName = False Then GoTo exitsub


    
'Turn off screen updating and display alerts
    With Application
        .ScreenUpdating = False: .DisplayAlerts = False
    End With
    
        'On Error GoTo exitsub
    Set wbRevDash = Workbooks.Open(fileName, False, True)
    
    With wbRevDash
        .Sheets("Data").Range("A8:AS64").ClearContents
        .Sheets("Data").Range("CH8:DZ64").ClearContents
    End With


'Now, transfer values from wbRevForecast to wbRevRash:
wbRevDash.Sheets("Data").Range("A8:AS64").Value = wbRevForecast.Sheets("FinalExport").Range("A8:AS64")
wbRevDash.Sheets("Data").Range('"CH8:DZ64").Value = wbRevForecast.Sheets("FinalExport").Range("AU8:AS64")
    
'Turn on screen updating and display alerts
    With Application
        .ScreenUpdating = True: .DisplayAlerts = True


'Selects Revenue dash worksheet
    wbRevDash.Sheets("Dash").Select
    
    End With
    
MsgBox "Data Export is complete. Validate data in dashboard"


End Sub
 
Last edited by a moderator:

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Add
Code:
.Value
to the end of both those lines & removed the apostrophe
Code:
([COLOR=#ff0000]'[/COLOR]"CH8:DZ64")
 
Upvote 0
Hmm, i missed that extra paranthesis - but removing the .value yielded the same result.

Blank cells in the destination workbook.
 
Upvote 0
Don't remove .value add it to the end of each of the 2 lines you highlighted
 
Upvote 0

Forum statistics

Threads
1,214,979
Messages
6,122,550
Members
449,088
Latest member
davidcom

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