Macro changes Conditional Formatting that's already preset - vba

I'm running a Macro that creates a new workbook and a tab in that workbook based on a dropdown selection. I'm running into issues with my conditional formatting. When I run the macro the conditional formatting rules are there but the color output changes. For example I have a conditional formatting that changes a number green based on another value but after running the macro the color changes to Orange. Doe's anyone know why?
Here's the code that I'm running
Sub BusinessPlan_Create()
Dim cell As Range
Dim counter As Long
Dim Dashboard As Worksheet
Dim newWB As Workbook
Dim wb1 As Workbook
Set wb1 = ThisWorkbook
Set newWB = Workbooks.Add
Set Dashboard = wb1.Sheets("Facility View")
Application.DisplayAlerts = False
For Each cell In wb1.Worksheets("dd").Range("$B3:$B87")
If cell.Value = "" Then
counter = counter + 1
Application.StatusBar = "Processing file: " & counter & "/1042"
Else
counter = counter + 1
Application.StatusBar = "Processing file: " & counter & "/1042"
With Dashboard
.Range("$B$1").Value = cell.Value
With wb1
.Worksheets("Facility View").Copy After:=newWB.Worksheets(1)
ActiveSheet.Cells.Copy
ActiveSheet.Range("A1").PasteSpecial Paste:=xlPasteSpecialOperationAdd
ActiveSheet.Name = cell.Value
End With
Application.CutCopyMode = False
End With
End If
Next cell
newWB.Activate
Call SortWorkBook2
Application.DisplayAlerts = True
Range("C6:D6").Select
Range(Selection, Selection.End(xlDown)).Select
Application.CutCopyMode = False
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Columns("C:C").EntireColumn.AutoFit
Columns("D:D").EntireColumn.AutoFit
Range("C4").Select
Application.CutCopyMode = False
End Sub

Related

Copy specific cells based on a criteria, to sheets with same label as the criteria in another workbook

I am trying to write a code for the following task, but I have been struggling a quite a bit.
I have 2 workbooks, wb1 and wb2.
wb1 has a table with a list of names in column A, then column B-V has the data I want to copy to the sheet with the same name as in column A but in a different book (wb2). The location its pasted to is also dependent on another criteria on the destination sheet in wb2.
so for example in wb1 "John" is the name in A1, switch to wb2, go to the sheet called John, check the criteria on cell A4 of this sheet:
There are 3 criteria which are: Teen, adult or Elder
If Teen, then copy B1 into B97, copy C1 into B135, copy D1 into B147 & B190, copy E4 into B1100
If Adult, then copy J1 into B97, copy F1 into B135, copy G1 into B147 & B190, copy H4 into B1100
If Elder, then copy B1 into B97, copy C1 into B135, copy D1 into B147 & B190, copy E4 into B1100, copy J1 into B113, copy F1 into B1910, copy G1 into B1473 & B1930, copy H4 into B1190
(The above is just an example, there is a more cells to copy paste than listed above)
This should be looped for all names in column A of wb1.
Below is what macro record gave me, but it doesn't record the criterias. Both workbooks will be open btw.
Sub Summary()
Dim wb1 As Workbook
Dim Sht As Worksheet
Dim Rng, Rng2 As Range
Set wb1= ThisWorkbook
Set Sht = MasterBook.Worksheets("Sheet")
Set Rng = Sht.Range("A2:A" & Sht.Cells(Sht.Rows.Count, "A").End(xlUp).Row)
Dim wb2 As Workbook
Dim cell As Range
For Each cell In Rng '<---Here is where my first problem is,
'not sure how to get the excel to switch to the sheet
'with the same name as in column A then check cell A4 for the criteria'
If cell.Value = "Teen" Then
Range("C12").Select
Selection.Copy
Windows("wb2.xlsx").Activate
ActiveWindow.SmallScroll Down:=81
Range("B97").Select
ActiveSheet.Paste
ActiveWindow.SmallScroll Down:=-9
Windows("wb1.xlsx").Activate
Range("D12").Select
Application.CutCopyMode = False
Selection.Copy
Windows("wb2.xlsx").Activate
ActiveWindow.SmallScroll Down:=12
Range("B95").Select
ActiveSheet.Paste
Windows("wb1.xlsx").Activate
Range("E12").Select
Application.CutCopyMode = False
Selection.Copy
Windows("wb2.xlsx").Activate
ActiveWindow.SmallScroll Down:=-45
Range("B47").Select
ActiveSheet.Paste
ActiveWindow.SmallScroll Down:=63
Range("B118").Select
ActiveSheet.Paste
Windows("wb1.xlsx").Activate
Range("F12").Select
Application.CutCopyMode = False
Selection.Copy
Windows("wb2.xlsx").Activate
ActiveWindow.SmallScroll Down:=48
Range("B163").Select
ActiveSheet.Paste
Windows("wb1.xlsx").Activate
Range("G12").Select
Application.CutCopyMode = False
Selection.Copy
Windows("wb2.xlsx").Activate
ActiveWindow.SmallScroll Down:=-66
Range("B93").Select
ActiveSheet.Paste
Windows("wb1.xlsx").Activate
Range("H12").Select
Application.CutCopyMode = False
Selection.Copy
Windows("wb2.xlsx").Activate
ActiveWindow.SmallScroll Down:=9
Range("B105").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
ActiveWindow.SmallScroll Down:=60
Range("B167").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Windows("wb1.xlsx").Activate
Range("I12").Select
Application.CutCopyMode = False
Selection.Copy
Windows("wb2.xlsx").Activate
ActiveWindow.SmallScroll Down:=-27
Range("B141").Select
ActiveSheet.Paste
Windows("wb1.xlsx").Activate
Range("J12").Select
Application.CutCopyMode = False
Selection.Copy
Windows("wb2.xlsx").Activate
Range("B145").Select
ActiveSheet.Paste
ActiveWindow.SmallScroll Down:=138
Windows("wb1.xlsx").Activate
Windows("wb2.xlsx").Activate
ActiveWindow.SmallScroll Down:=51
Range("B326").Select
ActiveSheet.Paste
ActiveWindow.SmallScroll Down:=12
Range("B339").Select
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = "1"
Range("B317").Select
ActiveCell.FormulaR1C1 = "1"
Range("B312").Select
ActiveCell.FormulaR1C1 = "1"
Windows("wb1.xlsx").Activate
Range("K12").Select
Selection.Copy
Windows("wb2.xlsx").Activate
Range("B107").Select
ActiveSheet.Paste
ActiveWindow.SmallScroll Down:=-63
Range("B49").Select
ActiveSheet.Paste
ActiveWindow.SmallScroll Down:=-9
Windows("wb1.xlsx").Activate
Windows("wb2.xlsx").Activate
ActiveWindow.SmallScroll Down:=306
Windows("wb1.xlsx").Activate
else If cell.Value = "Adult" Then
'<-----same stuff as above for different cells copy pasted'
else If cell.Value = "Elder" Then
'<-----same stuff as above for different cells copy pasted'
end if
End Sub
Also I don't know if the case function would be useful instead of the If statement here either.
Thanks a lot in advance
EDIT 1
I changed the code as suggested below
Sub Summary()
Dim wb1 As Workbook
Dim Sht As Worksheet
Dim Rng, Rng2 As Range
Dim wb2 As Workbook
Dim cell As Range
Set wb1 = ThisWorkbook
Set wb2 = Workbooks("Measure Templates.xlsx")
Set Sht = wb1.Worksheets("Summary")
Set Rng = Sht.Range("A5:A" & Sht.Cells(Sht.Rows.Count, "A").End(xlUp).Row)
For Each cell In Rng
Select Case wb2.Sheets(cell.Text).Range("A4").Value
Case "Standard Bathroom Template"
wb1.Sheet("Summary").Range("B5").Value = wb2.ActiveSheet.Range("B97") '<--- I'm getting an error here saying "Object doesn't support this property or method"
'I assume that this is not the right way to copy paste.
'I looked around but everything online uses a specific sheet name for destination
'which is not the case for me, it should be sheet with same name as in column A
wb1.Sheet("Summary").Range("C5").Value = wb2.ActiveSheet.Range("B117")
Case "Standard Kitchen Template"
wb1.Sheet("Summary").Range("B6").Value = wb2.ActiveSheet.Range("B97")
wb1.Sheet("Summary").Range("C6").Value = wb2.ActiveSheet.Range("B117")
Case "Standard Bathroom and Kitchen T"
wb1.Sheet("Summary").Range("B7").Value = wb2.ActiveSheet.Range("B97")
wb1.Sheet("Summary").Range("C7").Value = wb2.ActiveSheet.Range("B117")
End Select
Next cell
End Sub
Have updated and added a sheet variable (ws) which points to the relevant sheet for copying (it does not need to be selected or active).
Sub Summary()
Dim wb1 As Workbook
Dim Sht As Worksheet
Dim Rng, Rng2 As Range
Dim wb2 As Workbook
Dim cell As Range
Dim ws as Worksheet
Set wb1 = ThisWorkbook
Set wb2 = Workbooks("Measure Templates.xlsx")
Set Sht = wb1.Worksheets("Summary")
Set Rng = Sht.Range("A5:A" & Sht.Cells(Sht.Rows.Count, "A").End(xlUp).Row)
For Each cell In Rng
Set ws=wb2.Sheets(cell.Text)
Select Case ws.Range("A4").Value
Case "Standard Bathroom Template"
wb1.Sheet("Summary").Range("B5").Value = ws.Range("B97").Value
wb1.Sheet("Summary").Range("C5").Value = ws.Range("B117").Value
Case "Standard Kitchen Template"
wb1.Sheet("Summary").Range("B6").Value = ws.Range("B97").Value
wb1.Sheet("Summary").Range("C6").Value = ws.Range("B117").Value
Case "Standard Bathroom and Kitchen T"
wb1.Sheet("Summary").Range("B7").Value = ws.Range("B97").value
wb1.Sheet("Summary").Range("C7").Value = ws.Range("B117").Value
End Select
Next cell
End Sub

Form Option Button Excel VBA Not Working

I am trying to use multiple form option buttons as shown in the code below. The objective is to copy a range of data from one column and paste them and values in another column. Nothing fancy. So, I have multiple option buttons and one command button which is Button38. When I run the code, I don't get error messages and it's not working. Any help will be very appreciated, also I am new to VBA.
Sub Button38_Click()
Application.ScreenUpdating = False
Sheets("Sheet2").Visible = True
Sheets("Sheet2").Select
If OptionButton22 = True Then
Range("AI2:AI182").Copy
Range("AK2:AK182").PasteSpecial Paste:=xlPasteAllUsingSourceTheme, Operation:=xlNone _
, SkipBlanks:=False, Transpose:=False
ElseIf OptionButton23 = True Then
Range("AD2:AD182").Copy
Range("AK2:AK182").PasteSpecial Paste:=xlPasteAllUsingSourceTheme, Operation:=xlNone _
, SkipBlanks:=False, Transpose:=False
ElseIf OptionButton24 = True Then
Range("AE2:AE182").Copy
Range("AK2:AK182").PasteSpecial Paste:=xlPasteAllUsingSourceTheme, Operation:=xlNone _
, SkipBlanks:=False, Transpose:=False
End If
Sheets("Sheet1").Select
Sheets("Sheet2").Visible = False
Application.ScreenUpdating = True
End Sub
I re-set everything to Sheet1, and sheet2. Sheet1 being the one that has the Form option buttons, and sheet2 has the columns. I want sheet2 to be hidden all time.
You are using Form Control (Option Button). Also you do not need to unhide/hide the sheets. Let it remain hidden. This code will work and the range will get copy pasted even when Sheet2 is hidden.
Is this what you are trying?
Sub Button38_Click()
Dim wsThis As Worksheet, wsThat As Worksheet
Dim sCol As String
Set wsThis = Sheet2 '<~~ This sheet has the range
Set wsThat = Sheet1 '<~~ This sheet has FORM option buttons
With wsThis
If wsThat.Shapes("Option Button 22").OLEFormat.Object.Value = 1 Then sCol = "AI"
If wsThat.Shapes("Option Button 23").OLEFormat.Object.Value = 1 Then sCol = "AD"
If wsThat.Shapes("Option Button 24").OLEFormat.Object.Value = 1 Then sCol = "AE"
.Range(sCol & "2:" & sCol & "182").Copy
.Range("AK2:AK182").PasteSpecial Paste:=xlPasteAllUsingSourceTheme, _
Operation:=xlNone, SkipBlanks:=False, Transpose:=False
End With
End Sub
If you qualify all your objects to their parent the code should work. See below. (I also refactored the code a bit to make it cleaner, easier to maintain / read, and shorter).
Sub Button38_Click()
Dim ws1 as Worksheet
Set ws1 = Worksheets("Sheet1")
Application.ScreenUpdating = False
With Sheet2 'using the VBA sheet object name (change if needed)
.Visible = xlSheetVisible
Dim sCol As String
If .OptionButton22 = True Then
sCol = "AI"
ElseIf .OptionButton23 = True Then
sCol = "AD"
ElseIf .OptionButton24 = True Then
sCol = "AE"
End If
.Visible = xlSheetHidden
End With
ws1.Range("AK2:AK182").Value = ws1.Range(sCol & "2:" & sCol & "182").Value
'if you need the range theme copied as well use the code below
'With ws1
'.Range(sCol & "2:" & sCol & "182").Copy
'.Range("AK2:AK182").PasteSpecial Paste:=xlPasteAllUsingSourceTheme, Operation:=xlNone _
, SkipBlanks:=False, Transpose:=False
'End With
End Sub

How to use pastespecial with End(xlUp)

I am currently having an issue getting the data from one sheet to paste special into another sheet, I am trying to consolidate multiple files (same headers, differing number of rows) into one master sheet containing all the rows. At the moment I'm doing that by opening all the files, pulling in the tabs I want, copy and pasting the data, and then deleting the tabs. Yes I am sure there is an easier way, but I'm very new to VBA and am learning on the fly..here's what I have so far:
Sub ConsolidateSheets()
' open each file in folder
Dim Folder As String
Dim Files As String
Folder = "C:\Users\212411103\Documents\Risk Project Tracker\Risk Project Tracker Monthly\Monthly Data"
Files = Dir(Folder & "\*.xls")
Do While Files <> ""
Workbooks.Open Filename:=Folder & "\" & Files
Files = Dir
Loop
' pull in Risk Project Tracker tab from each file to new workbook
Dim wkb As Workbook
Dim sWksName As String
sWksName = "Risk Project Tracker"
For Each wkb In Workbooks
If wkb.Name <> ThisWorkbook.Name Then
wkb.Worksheets(sWksName).Copy _
Before:=ThisWorkbook.Sheets(1)
End If
Next
Set wkb = Nothing
Dim J As Integer
' add new sheet for combined data
On Error Resume Next
Sheets(1).Select
Worksheets.Add
Sheets(1).Name = "New Month"
' paste headers from first two rows into new sheet "New Month"
Sheets(2).Select
Range("A1:AH2").Select
Selection.Copy
Sheets("New Month").Select
Selection.PasteSpecial Paste:=xlPasteColumnWidths, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
ActiveSheet.Paste
Range("A1").Select
' work through sheets
For J = 2 To Sheets.Count ' from sheet 2 to last sheet
Sheets(J).Activate ' make the sheet active
Rows("1:2").Select
Selection.Delete Shift:=xlUp
Range("A1:AH500").Select
Selection.Copy
Sheets("New Month").Select
Selection.PasteSpecial Paste:=xlPasteColumnWidths, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Range("A1").Select
Next
' Delete tabs that are no longer needed i.e. the tabs from the 17 files
' For Each ws in Sheets
' Application.DisplayAlerts=False
' If ws.Name <> "New Month" Then ws.delete
' Next
' Application.DisplayAlerts=True
End Sub
It appears that the primary reason you are specifying the Range .PasteSpecial method is the carry-over of column widths which is done for every tab. Perhaps cycling through A:AH once and setting the column widths should be sufficient.
Sub ConsolidateSheets2()
Dim fldr As String, fn As String, sWksName As String, sNewWksName As String
Dim ws As Worksheet, wkb As Workbook
On Error GoTo bm_Safe_Exit
Application.ScreenUpdating = False
Application.EnableEvents = False
sWksName = "Risk Project Tracker"
fldr = "C:\Users\212411103\Documents\Risk Project Tracker\Risk Project Tracker Monthly\Monthly Data"
fn = Dir(fldr & "\*.xls")
sNewWksName = "New Month"
With ThisWorkbook
Do While fn <> ""
Set wkb = Workbooks.Open(Filename:=fldr & Chr(92) & fn)
If IsObject(wkb.Worksheets(sWksName)) Then
wkb.Worksheets(sWksName).Copy _
Before:=ThisWorkbook.Sheets(1 - CBool(Sheets(1).Name = sNewWksName))
On Error GoTo bm_Need_New_Month_ws
With .Worksheets(sNewWksName)
On Error GoTo bm_Safe_Exit
.Parent.Sheets(2).Range("A3:AH502").Copy _
Destination:=.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0)
End With
End If
wkb.Close False
fn = Dir
Loop
Application.DisplayAlerts = False
Do While Sheet.Count > 1: Sheets(2).Delete: Loop
End With
GoTo bm_Safe_Exit
bm_Need_New_Month_ws:
If Err.Number = 9 Then
With ThisWorkbook.Worksheets.Add(Before:=ThisWorkbook.Sheets(1))
.Name = sNewWksName
.Move Before:=Sheets(1)
.Parent.Sheets(2).Range("A1:AH2").Copy _
Destination:=.Range("A1")
For c = .Columns("AH:AH").Column To 1 Step -1
.Columns(c).ColumnWidth = _
.Parent.Sheets(2).Columns(c).ColumnWidth
Next c
End With
Resume
End If
bm_Safe_Exit:
Application.ScreenUpdating = True
Application.EnableEvents = True
End Sub

Worksheet not being protected

I have the following code that copies one worksheet to another and pastes only values however the code that protects the sheet is not working? what am I doing wrong here?
Sub GetQuote()
Range("AK548").Select
Selection.Copy
Range("AK549").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Dim ws As Worksheet
Dim sDataOutputName As String
With Application
.Cursor = xlWait
.StatusBar = "Saving Quote & Proposal Sheet..."
.ScreenUpdating = False
' Copy specific sheets
' *SET THE SHEET NAMES TO COPY BELOW*
' Array("Sheet Name", "Another sheet name", "And Another"))
' Sheet names go inside quotes, seperated by commas
On Error GoTo ErrCatcher
Sheets(Array("Quote & Proposal")).Copy
On Error GoTo 0
' Paste sheets as values
' Remove External Links, Hperlinks and hard-code formulas
' Make sure A1 is selected on all sheets
For Each ws In ActiveWorkbook.Worksheets
ws.Cells.Copy
ws.[A1].PasteSpecial Paste:=xlValues
ws.Cells.Hyperlinks.Delete
Application.CutCopyMode = False
Cells(1, 1).Select
ws.Activate
Next ws
Cells(1, 1).Select
sDataOutputName = ThisWorkbook.Path & "\" & ThisWorkbook.Worksheets("Quote Questions").Range("AK545").Value & ".xlsx"
' Save it with the NewName and in the same directory as original
ActiveWorkbook.SaveCopyAs sDataOutputName
ActiveWorkbook.Protect Password:="12345"
ActiveWorkbook.Close SaveChanges:=False
.Cursor = xlDefault
.StatusBar = False
.ScreenUpdating = True
End With
Exit Sub
ErrCatcher:
MsgBox "Specified sheets do not exist within this workbook"
End Sub
You are protecting the workbook and setting the password, on the next line of code you closing the workbook but not saving the changes.
Your code is showing work book protection, not work sheet protection. If you want to protect the sheet, use worksheet protection:
ws.Protect Password:="12345", DrawingObjects:=True, Contents:=True, Scenarios:=True
'ADD AND REMOVE PARAMETERS AS YOU WANT THEM
I put in: ActiveSheet.Protect Password:="12345" just above the line of code: ActiveWorkbook.SaveCopyAs sDataOutputName and it worked!

How do I remove links from a workbook linked to another

I have a sheet(Questions) in a workbook(Rating) that has a button at the bottom of the Questions sheet that copies sheet 2(quote) from the Rating workbook and pastes it in a new workbook that is named according to the quote number and then saved.
Here is that code:
Sub GetQuote()
Range("AK548").Select
Selection.Copy
Range("AK549").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Dim Output As Workbook
Dim FileName As String
Set Output = Workbooks.Add
FileName = ThisWorkbook.Path & "\" & ThisWorkbook.Worksheets("Questions").Range("AK545").Value & ".xls"
Output.SaveAs FileName
Application.DisplayAlerts = False
Output.Worksheets("Sheet1").Delete
ThisWorkbook.Worksheets(2).Copy Before:=Output.Worksheets("Sheet2")
Output.Worksheets(1).Name = "Sheet1"
Application.DisplayAlerts = True
Output.Protect Password:="12345"
Output.Save
End Sub
Now I intend on removing the links that now exsist between this new copy and the Quote sheet and only leave the values. How would I do this?
I have found this code that should delete the links that exsist:
Dim Cell As Range, FirstAddress As String, Temp As String
'delete all links from selected cells
Application.ScreenUpdating = False
With Selection
Set Cell = .Find("=*!", LookIn:=xlFormulas, searchorder:=xlByRows, _
LookAt:=xlPart, MatchCase:=True)
On Error GoTo Finish
FirstAddress = Cell.Address
Do
Temp = Cell
Cell.ClearContents
Cell = Temp
Set Cell = .FindNext(Cell)
Loop Until Cell Is Nothing Or Cell.Address = FirstAddress
End With
Finish:
All I have done extra is put this code in below the code that Names and copies the sheet and that did not work?
So now how would I combine these two pieces of code so that everything gets copied and the links removed?
I had existing workbooks that had external links that i needed to remove from the workbooks and then re save them.
This worked for me:
Sub BreakExternalLinks()
'PURPOSE: Breaks all external links that would show up in Excel's "Edit Links" Dialog Box
'SOURCE: www.TheSpreadsheetGuru.com/The-Code-Vault
Dim ExternalLinksArray As Variant
Dim wb As Workbook
Dim x As Long
Set wb = ActiveWorkbook
'Create an Array of all External Links stored in Workbook
ExternalLinksArray = wb.LinkSources(Type:=xlLinkTypeExcelLinks)
'if the array is not empty the loop Through each External Link in ActiveWorkbook and Break it
If IsEmpty(ExternalLinksArray) = False then
For x = 1 To UBound(ExternalLinksArray )
wb.BreakLink Name:=ExternalLinksArray (x), Type:=xlLinkTypeExcelLinks
Next x
end if
End Sub
This piece of code kills all connections in the active workbook... apologies, but can't remember where I got it.
'Kill Connections
If ActiveWorkbook.Connections.Count > 0 Then
For i = 1 To ActiveWorkbook.Connections.Count
ActiveWorkbook.Connections.Item(1).Delete
Next i
Else
End If
Tested with your code, this seems to work:
Dim Output As Workbook
Dim FileName As String
Set Output = Workbooks.Add
FileName = ThisWorkbook.Path & "\" & ThisWorkbook.Worksheets("Questions").Range("A1").Value & ".xls"
Output.SaveAs FileName
Application.DisplayAlerts = False
Output.Worksheets("Sheet1").Delete
ThisWorkbook.Worksheets(2).Copy Before:=Output.Worksheets("Sheet2")
Output.Worksheets(1).Name = "Sheet1"
Output.Worksheets(1).Select
If ActiveWorkbook.Connections.Count > 0 Then
For i = 1 To ActiveWorkbook.Connections.Count
ActiveWorkbook.Connections.Item(1).Delete
Next i
Else
End If
Application.DisplayAlerts = True
Output.Protect Password:="12345"
Output.Save
Perhaps it would help, if you don't use the actual copy & paste functions. If you only need the values of the cells, then change your macro to
Sub GetQuote()
Range("AK548").Select
Selection.Copy
Range("AK549").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Dim Output As Workbook
Dim FileName As String
Set Output = Workbooks.Add
FileName = ThisWorkbook.Path & "\" & ThisWorkbook.Worksheets("Questions").Range("AK545").Value & ".xls"
Output.SaveAs FileName
Application.DisplayAlerts = False
Dim v, r As Long, c As Long
With ThisWorkbook.Worksheets(2)
r = .Cells.SpecialCells(xlCellTypeLastCell).Row
c = .Cells.SpecialCells(xlCellTypeLastCell).Column
v = .Range(.Cells(1, 1), .Cells(r, c))
End With
With Output.Worksheets(1)
.Range(.Cells(1, 1), .Cells(r, c)) = v
End With
Application.DisplayAlerts = True
Output.Protect Password:="12345"
Output.Save
End Sub
This copies the values of your origin sheet to the new workbook sheet, without any links.
P.S.: Don't mix up ThisWorkbook and ActiveWorkbook. ThisWorkbook is the workbook where the macro is located (, but not necessarily the active workbook). ActiveWorkbook is the workbook, you see at that time.