Hi all,
I am extremely new to VBA and have never posted before, as I have been able to get everything I needed from others' questions.However, I have come up with an issue that I have been unable to solve. Sorry if it has already been answered in another thread and I was unable to find it!
From my main workbook, my macro is currently able to open another Excel workbook using File Browser, copy a selection of cells from that workbook (based on the contents of a cell in the original workbook), and finally switch back to the original workbook and paste those cells. The last thing I want to be able to do is close the second workbook (where the cell range was copied from) but I have been unable to figure it out. My current code is pasted below.
Can anyone help me with this? Thanks in advance!
Sub IndustryImport()
'
' IndustryImport Macro
'
Industry = Worksheets("Data").Range("B3")
Dim wb As Workbook
Set wb = ThisWorkbook
FileName = Application.GetOpenFilename
If FileName = False Then Exit Sub
Workbooks.Open (FileName)
Worksheets(Industry).Activate
Range("C4:C204").Select
Selection.Copy
ThisWorkbook.Activate
Worksheets("Data").Activate
Range("C21").Select
Selection.PasteSpecial Paste:=xlPasteValues
' ActiveWorkbook.Close (False)
End Sub
I am extremely new to VBA and have never posted before, as I have been able to get everything I needed from others' questions.However, I have come up with an issue that I have been unable to solve. Sorry if it has already been answered in another thread and I was unable to find it!
From my main workbook, my macro is currently able to open another Excel workbook using File Browser, copy a selection of cells from that workbook (based on the contents of a cell in the original workbook), and finally switch back to the original workbook and paste those cells. The last thing I want to be able to do is close the second workbook (where the cell range was copied from) but I have been unable to figure it out. My current code is pasted below.
Can anyone help me with this? Thanks in advance!
Sub IndustryImport()
'
' IndustryImport Macro
'
Industry = Worksheets("Data").Range("B3")
Dim wb As Workbook
Set wb = ThisWorkbook
FileName = Application.GetOpenFilename
If FileName = False Then Exit Sub
Workbooks.Open (FileName)
Worksheets(Industry).Activate
Range("C4:C204").Select
Selection.Copy
ThisWorkbook.Activate
Worksheets("Data").Activate
Range("C21").Select
Selection.PasteSpecial Paste:=xlPasteValues
' ActiveWorkbook.Close (False)
End Sub