BobtBuilder
New Member
- Joined
- Sep 1, 2023
- Messages
- 45
- Office Version
- 365
- Platform
- Windows
Hi there,
I can't seem to figure these two things out. I have a dashboard that serves as temporary worksheet. In this area I pull data from other worksheets manipulate them and then copy them back to their original worksheet.
After that I would need to copy the original formulas that were in the cells so I can pull data from other sheets.
I found a long way around the copy but what I thought would be the easy part was the reincorporating the formulas.
I set up a variable "Sh" that gives me the worksheet name.
1) I would like to use that variable to shorten the script and
2) be able to copy the formulas back to the cells.
Here is the code I currently have
Private Sub UpdateButton_Click()
'Create and set variables for the Call Tracking & Call Log worksheets
Dim Sh As Range
Set Sh = Range("A2") ' A2 is the cell where the worksheet name is located it is a drop down menu
If Sh = "IPC_CAD" Then
Range("D12").Copy Worksheets("IPC_CAD").Range("N7")
Range("D13").Copy Worksheets("IPC_CAD").Range("N8")
Range("D14").Copy Worksheets("IPC_CAD").Range("N9")
Range("D15").Copy Worksheets("IPC_CAD").Range("N10")
' This is where I tried to copy the formulas back but kept getting errors
'Range("D12").Formula = "=INDIRECT("" & A2 & " ! " & "n8")
' Copy "=INDIRECT(""&A2&"!"&"n9")" ("D13")
' Copy "=INDIRECT(""&A2&"!"&"n10")" ("D14")
' Copy "=INDIRECT(""&A2&"!"&"n11")" ("D13")
End If
If Sh = "IPC_USD" Then
Range("D12").Copy Worksheets("IPC_USD").Range("N7")
Range("D13").Copy Worksheets("IPC_USD").Range("N8")
Range("D14").Copy Worksheets("IPC_USD").Range("N9")
Range("D15").Copy Worksheets("IPC_USd").Range("N10")
End If
If Sh = "Bcon_CAD" Then
Range("D12").Copy Worksheets("Bcon_CAD").Range("N7")
Range("D13").Copy Worksheets("Bcon_CAD").Range("N8")
Range("D14").Copy Worksheets("Bcon_CAD").Range("N9")
Range("D15").Copy Worksheets("Bcon_CAD").Range("N10")
End If
If Sh = "Bcon_USD" Then
Range("D12").Copy Worksheets("Bcon_USD").Range("N7")
Range("D13").Copy Worksheets("Bcon_USD").Range("N8")
Range("D14").Copy Worksheets("Bcon_USD").Range("N9")
Range("D15").Copy Worksheets("Bcon_USD").Range("N10")
End If
If Sh = "Best_Flex_CAD" Then
Range("D12").Copy Worksheets("Best_Flex_CAD").Range("N7")
Range("D13").Copy Worksheets("Best_flex_CAD").Range("N8")
Range("D14").Copy Worksheets("Best_flex_CAD").Range("N9")
Range("D15").Copy Worksheets("Best_flex_CAD").Range("N10")
End If
If Sh = "Best_Flex_USD" Then
Range("D12").Copy Worksheets("Best_Flex_USD").Range("N7")
Range("D13").Copy Worksheets("Best_flex_USD").Range("N8")
Range("D14").Copy Worksheets("Best_flex_USD").Range("N9")
Range("D15").Copy Worksheets("Best_flex_USD").Range("N10")
End If
If Sh = "Bc_chk" Then
Range("D12").Copy Worksheets("Bc_chk").Range("N7")
Range("D13").Copy Worksheets("Bc_chk").Range("N8")
Range("D14").Copy Worksheets("Bc_chk").Range("N9")
Range("D15").Copy Worksheets("Bc_chk").Range("N10")
End If
If Sh = "Bc_USD" Then
Range("D12").Copy Worksheets("Bc_usd").Range("N7")
Range("D13").Copy Worksheets("Bc_usd").Range("N8")
Range("D14").Copy Worksheets("Bc_usd").Range("N9")
Range("D15").Copy Worksheets("Bc_usd").Range("N10")
End If
If Sh = "Bc_esave" Then
Range("D12").Copy Worksheets("Bc_esave").Range("N7")
Range("D13").Copy Worksheets("Bc_esave").Range("N8")
Range("D14").Copy Worksheets("Bc_esave").Range("N9")
Range("D15").Copy Worksheets("Bc_esave").Range("N10")
End If
End Sub
Thank you
I can't seem to figure these two things out. I have a dashboard that serves as temporary worksheet. In this area I pull data from other worksheets manipulate them and then copy them back to their original worksheet.
After that I would need to copy the original formulas that were in the cells so I can pull data from other sheets.
I found a long way around the copy but what I thought would be the easy part was the reincorporating the formulas.
I set up a variable "Sh" that gives me the worksheet name.
1) I would like to use that variable to shorten the script and
2) be able to copy the formulas back to the cells.
Here is the code I currently have
Private Sub UpdateButton_Click()
'Create and set variables for the Call Tracking & Call Log worksheets
Dim Sh As Range
Set Sh = Range("A2") ' A2 is the cell where the worksheet name is located it is a drop down menu
If Sh = "IPC_CAD" Then
Range("D12").Copy Worksheets("IPC_CAD").Range("N7")
Range("D13").Copy Worksheets("IPC_CAD").Range("N8")
Range("D14").Copy Worksheets("IPC_CAD").Range("N9")
Range("D15").Copy Worksheets("IPC_CAD").Range("N10")
' This is where I tried to copy the formulas back but kept getting errors
'Range("D12").Formula = "=INDIRECT("" & A2 & " ! " & "n8")
' Copy "=INDIRECT(""&A2&"!"&"n9")" ("D13")
' Copy "=INDIRECT(""&A2&"!"&"n10")" ("D14")
' Copy "=INDIRECT(""&A2&"!"&"n11")" ("D13")
End If
If Sh = "IPC_USD" Then
Range("D12").Copy Worksheets("IPC_USD").Range("N7")
Range("D13").Copy Worksheets("IPC_USD").Range("N8")
Range("D14").Copy Worksheets("IPC_USD").Range("N9")
Range("D15").Copy Worksheets("IPC_USd").Range("N10")
End If
If Sh = "Bcon_CAD" Then
Range("D12").Copy Worksheets("Bcon_CAD").Range("N7")
Range("D13").Copy Worksheets("Bcon_CAD").Range("N8")
Range("D14").Copy Worksheets("Bcon_CAD").Range("N9")
Range("D15").Copy Worksheets("Bcon_CAD").Range("N10")
End If
If Sh = "Bcon_USD" Then
Range("D12").Copy Worksheets("Bcon_USD").Range("N7")
Range("D13").Copy Worksheets("Bcon_USD").Range("N8")
Range("D14").Copy Worksheets("Bcon_USD").Range("N9")
Range("D15").Copy Worksheets("Bcon_USD").Range("N10")
End If
If Sh = "Best_Flex_CAD" Then
Range("D12").Copy Worksheets("Best_Flex_CAD").Range("N7")
Range("D13").Copy Worksheets("Best_flex_CAD").Range("N8")
Range("D14").Copy Worksheets("Best_flex_CAD").Range("N9")
Range("D15").Copy Worksheets("Best_flex_CAD").Range("N10")
End If
If Sh = "Best_Flex_USD" Then
Range("D12").Copy Worksheets("Best_Flex_USD").Range("N7")
Range("D13").Copy Worksheets("Best_flex_USD").Range("N8")
Range("D14").Copy Worksheets("Best_flex_USD").Range("N9")
Range("D15").Copy Worksheets("Best_flex_USD").Range("N10")
End If
If Sh = "Bc_chk" Then
Range("D12").Copy Worksheets("Bc_chk").Range("N7")
Range("D13").Copy Worksheets("Bc_chk").Range("N8")
Range("D14").Copy Worksheets("Bc_chk").Range("N9")
Range("D15").Copy Worksheets("Bc_chk").Range("N10")
End If
If Sh = "Bc_USD" Then
Range("D12").Copy Worksheets("Bc_usd").Range("N7")
Range("D13").Copy Worksheets("Bc_usd").Range("N8")
Range("D14").Copy Worksheets("Bc_usd").Range("N9")
Range("D15").Copy Worksheets("Bc_usd").Range("N10")
End If
If Sh = "Bc_esave" Then
Range("D12").Copy Worksheets("Bc_esave").Range("N7")
Range("D13").Copy Worksheets("Bc_esave").Range("N8")
Range("D14").Copy Worksheets("Bc_esave").Range("N9")
Range("D15").Copy Worksheets("Bc_esave").Range("N10")
End If
End Sub
Thank you