Jeffreyxx01
Board Regular
- Joined
- Oct 23, 2017
- Messages
- 156
Hi guys,
I have my macro here and I would like it to copy the range if the Cell W5 is Yes and if NO copy just the selected range
I have the macro but the yes/no thing is quite hard.
Thanks for the help.
I have my macro here and I would like it to copy the range if the Cell W5 is Yes and if NO copy just the selected range
I have the macro but the yes/no thing is quite hard.
Thanks for the help.
Code:
Sub OpenFile_PW()
Dim Fname As String
Dim Wbk As Workbook
Dim Sht As Worksheet
Set Sht = ActiveWorkbook.Sheets("PW")
ChDrive "W:"
ChDir "W:\Insights Team\ALL ACADEMIC\Reporting\Weekly RAM\Pathways"
Fname = Application.GetOpenFilename(FileFilter:="xls Files (*.xls*), *.xls*", Title:="Select a file", MultiSelect:=False)
If Fname = "False" Then
MsgBox "no file selected"
Exit Sub
Else
Set Wbk = Workbooks.Open(Fname)
With Wbk.Sheets("Summary for BP")
Sht.Range("s6:V27").ClearContents
.Range("i7:L28").Copy
Sht.Range("s6").PasteSpecial xlPasteValues
If Range("W5")= Yes
Sht.Range("W6:W27").ClearContents
.Range("M7:M28").Copy
Sht.Range("W6").PasteSpecial xlPasteValues
Else: Range("W5") = No
Sht.Range("s6:V27").ClearContents
.Range("i7:L28").Copy
Sht.Range("s6").PasteSpecial xlPasteValues
Application.CutCopyMode = False
End With
Application.DisplayAlerts = False
Wbk.Close , False
End If
End Sub