Paste values only

Victtor

Board Regular
Joined
Jan 4, 2007
Messages
170
Office Version
  1. 365
Platform
  1. Windows
Here is a macro I recorded. I need this to paste values only in the new sheet. The blank cells must truly be blank and not with a formula in them. The online webpage I upload this to will return an error if there is data in the blank cells. Thanks for your help


Sub MBMexport()
'
' MBMexport Macro
'
' Keyboard Shortcut: Ctrl+Shift+V
'
Range("D5").Select
Sheets("export").Select
Sheets("export").Copy Before:=Workbooks("MBMexportfile.csv").Sheets(1)
ActiveWorkbook.Save
ActiveWorkbook.Save
ActiveWindow.Close
End Sub
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
How about
Code:
Sub MBMexport()
'
' MBMexport Macro
'
' Keyboard Shortcut: Ctrl+Shift+V
'
Range("D5").Select
Sheets("export").Select
Sheets("export").Copy Before:=Workbooks("MBMexportfile.csv").Sheets(1)
With ActiveSheet.UsedRange
   .Value = .Value
End With
ActiveWorkbook.Save
ActiveWorkbook.Save
ActiveWindow.Close
End Sub
 
Upvote 0
How about
Code:
Sub MBMexport()
'
' MBMexport Macro
'
' Keyboard Shortcut: Ctrl+Shift+V
'
Range("D5").Select
Sheets("export").Select
Sheets("export").Copy Before:=Workbooks("MBMexportfile.csv").Sheets(1)
With ActiveSheet.UsedRange
   .Value = .Value
End With
ActiveWorkbook.Save
ActiveWorkbook.Save
ActiveWindow.Close
End Sub

Something is still off. It gave me the error message again and showed every line after the last line with data in it as having a non numeric value in it.

I always end up copying the cells in columns A and B that have numeric values in them to columns C and D and then just deleting columns A and B. This workaround fixes the problem, I just need a macro that can eliminate this manual step
 
Upvote 0
What formulae do those columns contain?
 
Upvote 0
What formulae do those columns contain?

Cells A1:A187 in column A of the source file contain the following:
=IFERROR(INDEX(Source!$C$2:$C$187,AGGREGATE(15,6,ROW($C$2:$C$187)/((Source!$I$2:$I$187>0)),ROWS(A$2:A2))-(2-1),1),"")

Cells B1:B187 in column b of the source file contain the following:
=IFERROR(INDEX(Source!$I$2:$I$187,AGGREGATE(15,6,ROW($C$2:$C$187)/((Source!$I$2:$I$187>0)),ROWS(A$2:A2))-(2-1),1),"")

So the following Macro in the first post copies all cells with data in them and pastes it into the destination MBMExport.csv file

Sub MBMexport()
'
' MBMexport Macro
'
' Keyboard Shortcut: Ctrl+Shift+V
'
Range("D5").Select
Sheets("export").Select
Sheets("export").Copy Before:=Workbooks("MBMexportfile.csv").Sheets(1)
ActiveWorkbook.Save
ActiveWorkbook.Save
ActiveWindow.Close
End Sub
 
Upvote 0
@Victtor, what happens with the macro below?
Make sure you have a backup of the data before running as it is deleting columns and rows.

Code:
Sub MBMexport()
    '
    ' MBMexport Macro
    '
    ' Keyboard Shortcut: Ctrl+Shift+V
    '

    Dim LastRow As Long, LastCol As Long
    Application.ScreenUpdating = False

    With Workbooks("MBMexportfile.csv")
        Sheets("export").Copy Before:=.Sheets(1)
        .Sheets(1).UsedRange.Value = .Sheets(1).UsedRange.Value

        On Error Resume Next

        With .Sheets(1)
            LastRow = .Cells.Find(What:="*", After:=.Range("A1"), LookIn:=xlValues, _
                                  LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
            LastCol = .Cells.Find(What:="*", After:=.Range("A1"), LookIn:=xlValues, _
                                  LookAt:=xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlPrevious).Column
            .Range(.Cells(1, LastCol + 1), .Cells(Rows.Count, Columns.Count)).Delete
            .Range(.Cells(LastRow + 1, 1), .Cells(Rows.Count, Columns.Count)).Delete
        End With

        On Error GoTo 0

    End With


    Application.ScreenUpdating = True

    '    ActiveWorkbook.Save
    '    ActiveWorkbook.Save
    '    ActiveWindow.Close
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

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