I have an xlsb file that contains VBA macros, a csv file that contains a bunch of values. (when the macro is running, the csv file is already open)
And I need to open a xlsm file and copy a range of data from this file to a range of cells in the csv. code below is copying the data to the xlsb file for some reason
I defined wb2, ws2 as csv, wb3 and ws3 are the xlsm. I must be missing something very simple here...
And I need to open a xlsm file and copy a range of data from this file to a range of cells in the csv. code below is copying the data to the xlsb file for some reason
I defined wb2, ws2 as csv, wb3 and ws3 are the xlsm. I must be missing something very simple here...
VBA Code:
Sub OpenQuoteFile()
Dim wb2 As Workbook
Dim ws2 As Worksheet
Dim wb3 As Workbook
Dim ws3 As Worksheet
Application.ScreenUpdating = False
Dim FileName As Variant
FileName = Application.GetOpenFilename(filefilter:="Excel Macro-Enabled Workbook (*.xlsm),*.xlsm", MultiSelect:=False)
If FileName = False Then Exit Sub
Set wb2 = ActiveWorkbook
Set ws2 = ActiveSheet
Set wb3 = Workbooks.Open(FileName)
Set ws3 = wb3.Worksheets("QUOTE")
wb2.Activate
ws2.Activate
Dim i As Long
For i = 19 To 46
If ws3.Range("D" & i).Value <> "" Then
ws3.Range("D" & i).Copy
ws2.Range("S" & i - 18).PasteSpecial xlPasteValues 'Copy as values
If ws3.Range("D" & i).MergeCells Then
ws2.Range("S" & i - 18).UnMerge
End If
End If
Next i
Application.CutCopyMode = False
Application.ScreenUpdating = True
End Sub