"if instr" not working with a loop - vba

I am a VBA beginner. I am trying to build a macro that would copy and paste (value) an entire row to a new sheet based on a differentiation criteria. The differentiation criteria, in this case, would be the content of specific cell. In other words, if the cell contains the word "Caviar" then copy the row into sheet 1 otherwise copy into sheet 2. The following macro works when I run it manually (row one by one).
Sub Search_and_copy()
Dim rng As String
rng = Sheets("40").Range("F11").Value
Dim rowNo As Integer
rowNo = 6
Dim celltxt As String
celltxt = Sheets("40").Range("P11").Value
rowNo = 6
If Sheets("40").Range("F11").Value = "254" Then
If InStr(celltxt, "CAVIAR") Then
Rows("11:11").Select
Selection.Copy
Sheets("Sheet1").Select
If IsEmpty(Cells(rowNo, 1)) Then
Sheets("Sheet1").Cells(rowNo, 1).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Else: Do Until IsEmpty(Cells(rowNo, 1))
rowNo = rowNo + 1
Loop
Sheets("Sheet1").Cells(rowNo, 1).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
End If
Sheets("40").Select
Application.CutCopyMode = False
Selection.Delete Shift:=xlUp
Else
Rows("11:11").Select
Selection.Copy
Sheets("Sheet2").Select
If IsEmpty(Cells(rowNo, 1)) Then
Sheets("Sheet2").Cells(rowNo, 1).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Else: Do Until IsEmpty(Cells(rowNo, 1))
rowNo = rowNo + 1
Loop
Sheets("Sheet2").Cells(rowNo, 1).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
End If
Sheets("40").Select
Application.CutCopyMode = False
Selection.Delete Shift:=xlUp
End If
End If
End Sub
However, as soon as I introduce a loop (see code below), the differentiation is no longer properly made and all rows are copied into the same worksheet. What am I doing wrong?
Sub Search_and_copy()
Dim rng As String
rng = Sheets("40").Range("F11").Value
Dim rowNo As Integer
rowNo = 6
Dim celltxt As String
celltxt = Sheets("40").Range("P11").Value
Do Until IsEmpty(Sheets("40").Range("F11").Value)
rowNo = 6
If Sheets("40").Range("F11").Value = "254" Then
If InStr(celltxt, "CAVIAR") Then
Rows("11:11").Select
Selection.Copy
Sheets("Sheet1").Select
If IsEmpty(Cells(rowNo, 1)) Then
Sheets("Sheet1").Cells(rowNo, 1).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Else: Do Until IsEmpty(Cells(rowNo, 1))
rowNo = rowNo + 1
Loop
Sheets("Sheet1").Cells(rowNo, 1).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
End If
Sheets("40").Select
Application.CutCopyMode = False
Selection.Delete Shift:=xlUp
Else
Rows("11:11").Select
Selection.Copy
Sheets("Sheet2").Select
If IsEmpty(Cells(rowNo, 1)) Then
Sheets("Sheet2").Cells(rowNo, 1).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Else: Do Until IsEmpty(Cells(rowNo, 1))
rowNo = rowNo + 1
Loop
Sheets("Sheet2").Cells(rowNo, 1).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
End If
Sheets("40").Select
Application.CutCopyMode = False
Selection.Delete Shift:=xlUp
End If
End If
Loop
End Sub

The (first) problem is that you never change the value of celltxt inside your loop. After you read Sheets("40").Range("P11").Value into the string, you never change it. This means that InStr(celltxt, "CAVIAR") will always be the same until the Sub ends. All you should need to do is update it inside your loop.
One other thing to do while you're at it is to apply a little DRY and extract your common code into a function. The only difference between your If and Else is the sheet name. Try something like this:
Sub Search_and_copy()
Dim celltxt As String
Do Until IsEmpty(Sheets("40").Range("F11").Value)
celltxt = Sheets("40").Range("P11").Value
If Sheets("40").Range("F11").Value = "254" Then
If InStr(celltxt, "CAVIAR") Then
DontRepeatYourself "Sheet1"
Else
DontRepeatYourself "Sheet2"
End If
End If
Loop
End Sub
Private Sub DontRepeatYourself(sheet As String)
Dim rowNo As Long
rowNo = 6
Rows("11:11").Select
Selection.Copy
Sheets(sheet).Select
Do Until IsEmpty(Cells(rowNo, 1))
rowNo = rowNo + 1
Loop
Sheets(sheet).Cells(rowNo, 1).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Sheets("40").Select
Application.CutCopyMode = False
Selection.Delete Shift:=xlUp
End Sub

Related

Keeping Conditional Formatting

Hi I'm busy with a VBA macro that copies data from one sheet to another, problem is whenever i paste the data to the other sheet, the conditional formatting falls off.It messes up with what i want to achieve. Isn't there a code I could use to keep conditional formatting. here is my code:
'In this example I am Copying the Data from Sheet1 (Source) to Sheet2
(Destination)
Sub sbCopyRangeToAnotherSheet()
'Method 1
Application.ScreenUpdating = False
'Set active sheet as current sheet
temp = ActiveSheet.Index
'Clear contents in sheet 1
Sheets("Sheet1").Select
Range("B22").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.ClearContents
'Clear Specials in Sheet 1
Range("B13").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.ClearContents
'Return to current sheet and copy required contents
Sheets(temp).Select
Range("D51").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
'Paste data in sheet 1
Worksheets("Sheet1").Activate
k = Worksheets("Sheet1").Cells(Rows.Count, 1).End(xlUp).Row
Range("B22").Select ' kindly change the code to suit your paste location
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
'Copy specials over to sheet1
Sheets(temp).Select
Range("i36").Select
p = Range(Selection, Selection.End(xlDown)).Count
j = 0
For k = 1 To p
Sheets(temp).Select
t = Range("i36").Offset(k - 1, 0).Value
s = Range("j36").Offset(k - 1, 0).Value
If t = True Then
Sheets("Sheet1").Select
j = j + 1
Range("b13").Offset(j - 1, 0).Value = s
Else: End If
Next k
'Delete Empty Rows In UPL
Dim iRow As Long, lastRow As Long
Dim ws As Worksheet
Set ws = Worksheets("Sheet1") 'qualify your sheet
lastRow = ws.Range("A" & ws.Rows.Count).End(xlUp).Row 'find last used row
For iRow = lastRow To 1 Step -1 'run from last used row backwards to row 1
If ws.Cells(iRow, 3).Text = "#N/A" Or _
ws.Cells(iRow, 4).Text = "#N/A" Then
ws.Rows(iRow).Delete
End If
Next iRow
' Paste Unit Into UPL
Sheets(temp).Select
temp = Sheets(temp).Range("d35").Value
model = Range("D26").Value
Sheets("Sheet1").Select
Range("B11").Value = temp & " " & model
End Sub
Please Assist
so I recommend to replace this:
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
with this:
Selection.PasteSpecial Paste:=xlPasteAllMergingConditionalFormats, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False 'so that Excel will not be in the copy mode

Excel Macro - Repeat a process

I have a recorded macro, for a simple process in Excel. However, I need it to repeat the process for about 80 lines. Here is the code I have for the first 4 lines. Any help on a simple way to do this would be appreciated. Thank you.
Sub Macro2()
'
' Macro2 Macro
'
'
Range("A5").Select
ActiveCell.FormulaR1C1 = "1"
Sheets("EST COST").Select
Range("D6").Select
Selection.Copy
Sheets("IL").Select
Range("I5").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("A5").Select
ActiveCell.FormulaR1C1 = "0"
Range("A6").Select
ActiveCell.FormulaR1C1 = "1"
Sheets("EST COST").Select
Range("D6").Select
Selection.Copy
Sheets("IL").Select
Range("I6").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("A6").Select
ActiveCell.FormulaR1C1 = "0"
Range("A7").Select
ActiveCell.FormulaR1C1 = "1"
Sheets("EST COST").Select
Range("D6").Select
Selection.Copy
Sheets("IL").Select
Range("I7").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("A7").Select
ActiveCell.FormulaR1C1 = "0"
End Sub
You want to use a for...next loop. Some Googling should get you quite far, but here's a flavour of the general idea:
dim startRow as integer
dim endRow as integer
dim myColumn as integer
startRow = 5
endRow = 45
For activeRow = startRow to endRow
[do something]
myColumn = [some column number]
cells(activeRow, myColumn).Value = [something]
Next activeRow
Something like this
Sub test()
Dim wsTarget As Worksheet
Dim wsSource As Worksheet
Set wsTarget = Sheets("EST COST")
Set wsSource = Sheets("IL")
Dim intIndex As Integer
For intIndex = 5 To 85
wsTarget.Range("A" & intIndex).FormulaR1C1 = "1"
wsTarget.Range("D" & intIndex).Copy
With wsSource
.Range("I" & intIndex).PasteSpecial Paste:=xlPasteValues _
, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
.Range("A" & intIndex).FormulaR1C1 = "0"
End With
Next
End Sub
To keep your code as similar as you have it, try this:
Sub test()
Dim rng As Range
Dim i&
For i = 5 To 40
' WHAT SHEET IS YOUR DEFAULT RANGES ON?
Range("A" & i).FormulaR1C1 = "1" ' what sheet is this on? We want to be explicit
Sheets("EST COST").Range("D" & i + 1).Copy
Sheets("IL").Range("I" & i).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("A" & i).FormulaR1C1 = "0"
Next i
End Sub
I'm assuming you want the pasted range to be offset one row (you copy A5, pasted into I6). As I noted though, I'd prefer to know what sheet your ranges to be copied are on, so we can add that worksheet to the ranges (Range("A"& i)... should really be Sheets("mainSheet").Range("A"&i)...)

Calculate, Copy and Paste to a given value in VBA

I am fairly new to VBA. I am trying to automate iterations based on the no. of iterations specified in cell "E2". I want excel to Autofill down column A from cell "A4" to the value of cell "E2" e.g if E2 = 100, Excel will autofill series 1,2,3...down to 100.
I then want excel to continuosly calculate the value of cell "B2" then copy and paste each result down column B, starting at "B4" and stops at the value of iterations "E2"
I have the following code for the "Autofill"
Sub Monte3()
Dim srcRange As Range
Dim destRange As Range
Range("A5:A1000000").ClearContents
Set srcRange = ActiveSheet.Range("A4")
Set destRange = ActiveSheet.Range("A4:A103")
srcRange.AutoFill destRange, xlFillSeries
End Sub
I have recorded the following Macro for copy paste
Sub Macro10()
Application.CutCopyMode = False
Calculate
Range("B2").Select
Selection.Copy
Range("B4").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Calculate
Range("B2").Select
Selection.Copy
Range("B5").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Calculate
Range("B2").Select
Selection.Copy
Range("B6").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Calculate
Range("B2").Select
Selection.Copy
Range("B7").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
What's the easiest way to do this?
A nice For Each Next Loop should work. See the code below. I took some guesses on some of the range references based on what you wrote above, but you should be able to modify it easily to suit your needs.
Sub Monte3()
Dim srcRange As Range, cel As Range
Dim wks As Worksheet
Set wks = Sheets("Sheet1") 'replace Sheet1 with your sheet name
With wks
.Range("B5:B1000000").ClearContents
Set srcRange = .Range("B4:B" & .Range("E2").Value + 4) 'will plug the number in from E2 as the row and adds 4 since you are starting at row 4
For Each cel In srcRange
With .Range("B2")
.Calculate
.Copy
End With
cel.PasteSpecial xlPasteValues
Next
End With
End Sub

VBA Loop to Copy Columns

I want to copy a defined number (lets say 10) of rows from one sheet ("Data") and paste it in another sheet ("Input). This will cause a bunch of stuff to calculate. Then I want to copy said calculated data (6 rows) from ("Input") to ("Data") and paste in a results table. THen I would repeat this a defined number of times for a certain number of columns (lets say 10).
I tried writing the code but it has literally been years since I have written code.
I used the Record Marco thing and got this:
Sub Macro2()
'
' Macro2 Macro
'
'
Range("C5:C14").Select
Selection.Copy
Sheets("Input").Select
Range("C5").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("P12:P19").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Data").Select
Range("C22").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("D5:D14").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Input").Select
Range("C5").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("P12:P19").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Data").Select
Range("D22").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("G16").Select
End Sub
I hope this makes sense
Sub Macro2()
Const NUM_TIMES As Long = 10
Dim shtInput As Worksheet, shtData As Worksheet
Dim rngCopy As Range, i As Long
Set shtInput = Sheets("Input")
Set shtData = Sheets("Data")
Set rngCopy = shtData.Range("C5:C15")
For i = 1 To NUM_TIMES
With shtInput
.Range("C5").Resize(rngCopy.Rows.Count, 1).Value = rngCopy.Value
.Calculate
rngCopy(1).Offset(17, 0).Resize(8, 1).Value = .Range("P12:P19").Value
End With
Set rngCopy = rngCopy.Offset(0, 1)
Next i
End Sub

Copy Range From One Sheet Paste Part of Range In Same Sheet Based On Cell Value On Another Sheet

Right now I've created a code to copy values from one range to another range based on the value from another sheet (the copy and paste happens on one sheet).
But because this value can be one of twelve values, the range that is being copied and pasted becomes smaller.
Because I'm not adept at VBA I created dozens of copy ranges and dozens of paste ranges in Excel to handle ElseIf statements via VBA to copy and paste depending on what the cell value is in the other sheet.
I'm curious, is there a way to make my code more optimized and have less named ranges in my workbook?
Any help would be appreciated, here's my code pasted below (each named range for both the copy and paste is simply one less column due to what the selections can be in the first sheet):
SubTest()
If ws0.Range("D6") = "BUD" Then
ws1.Range("CopyFormulasFT").Select
Selection.Copy
ws1.Range("PasteFormulasFT").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, _
SkipBlanks:=True, Transpose:=False
ElseIf ws0.Range("D6") = "F01" Then
ws1.Range("CopyFormulasFTOneEleven").Select
Selection.Copy
ws1.Range("PasteFormulasFTOneEleven").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, _
SkipBlanks:=True, Transpose:=False
ElseIf ws0.Range("D6") = "F02" Then
ws1.Range("CopyFormulasFTTwoTen").Select
Selection.Copy
ws1.Range("PasteFormulasFTTwoTen").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, _
SkipBlanks:=True, Transpose:=False
ElseIf ws0.Range("D6") = "F03" Then
ws1.Range("CopyFormulasFTThreeNine").Select
Selection.Copy
ws1.Range("PasteFormulasFTThreeNine").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, _
SkipBlanks:=True, Transpose:=False
ElseIf ws0.Range("D6") = "F04" Then
ws1.Range("CopyFormulasFTFourEight").Select
Selection.Copy
ws1.Range("PasteFormulasFTFourEight").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, _
SkipBlanks:=True, Transpose:=False
ElseIf ws0.Range("D6") = "F05" Then
ws1.Range("CopyFormulasFTFiveSeven").Select
Selection.Copy
ws1.Range("PasteFormulasFTFiveSeven").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, _
SkipBlanks:=True, Transpose:=False
ElseIf ws0.Range("D6") = "F06" Then
ws1.Range("CopyFormulasFTSixSix").Select
Selection.Copy
ws1.Range("PasteFormulasFTSixSix").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, _
SkipBlanks:=True, Transpose:=False
ElseIf ws0.Range("D6") = "F07" Then
ws1.Range("CopyFormulasFTSevenFive").Select
Selection.Copy
ws1.Range("PasteFormulasFTSevenFive").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, _
SkipBlanks:=True, Transpose:=False
ElseIf ws0.Range("D6") = "F08" Then
ws1.Range("CopyFormulasFTEightFour").Select
Selection.Copy
ws1.Range("PasteFormulasFTEightFour").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, _
SkipBlanks:=True, Transpose:=False
ElseIf ws0.Range("D6") = "F09" Then
ws1.Range("CopyFormulasFTNineThree").Select
Selection.Copy
ws1.Range("PasteFormulasFTNineThree").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, _
SkipBlanks:=True, Transpose:=False
ElseIf ws0.Range("D6") = "F10" Then
ws1.Range("CopyFormulasFTTenTwo").Select
Selection.Copy
ws1.Range("PasteFormulasFTTenTwo").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, _
SkipBlanks:=True, Transpose:=False
ElseIf ws0.Range("D6") = "F11" Then
ws1.Range("CopyFormulasFTElevenOne").Select
Selection.Copy
ws1.Range("PasteFormulasFTElevenOne").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, _
SkipBlanks:=True, Transpose:=False
End If
End Sub
Using string manipulation and a loop you could greatly reduce the size of that code:
dim arrStrings(1 to 11) as string
arrStrings(1) = "OneEleven"
arrStrings(2) = "TwoTen"
arrStrings(2) = "ThreeNine"
...
arrStrings(11) = "NineThree"
dim i as integer
for i = 1 to 11
If ws0.Range("D6") = "F"+ strings.trim(str(i)) Then
ws1.Range("CopyFormulasFT" + arrStrings(i)).Select
Selection.Copy
ws1.Range("PasteFormulasFT" + arrStrigns(i)).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, _
SkipBlanks:=True, Transpose:=False
end if
next i
if the actual code is something like this
"oneone", "onetwo", "onethree", ..., "oneeleven", "twoone", "twotwo", "twothree", ... "twoeleven" ...
(11x11 strings)
you could use a double loop over this array:
dim arrStrings(1 to 11) as string
arrStrings(1) = "One"
arrStrings(2) = "Two"
arrStrings(2) = "Three"
...
arrStrings(11) = "Nine"
and you can create the string like this
Str = "CopyFormulasFT"+ arrstrings(i) + arrstrings(j)
Another approach, this one much more flexible and easier to update:
Sub CondCopy()
Dim ws0 As Worksheet, ws1 As Worksheet
Dim str0 As String, str1 As String, str2 As String
Dim strCond As String, ArrLoc As Long
Dim strCopy As String, strPaste As String, strNum As String
With ThisWorkbook
Set ws0 = .Sheets("Sheet1")
Set ws1 = .Sheets("Sheet2")
End With
str0 = ";One;Two;Three;Four;Five;Six;Seven;Eight;Nine;Ten;Eleven"
str1 = ";Eleven;Ten;Nine;Eight;Seven;Six;Five;Four;Three;Two;One"
str2 = "BUD;F01;F02;F03;F04;F05;F06;F07;F08;F09;F10;F11"
strCond = ws0.Range("D6").Value
ArrLoc = Application.Match(strCond, Split(str2, ";"), 0) - 1
strNum = Split(str0, ";")(ArrLoc) & Split(str1, ";")(ArrLoc)
strCopy = "CopyFormulasFT" & strNum
strPaste = "PasteFormulasFT" & strNum
With ws1
.Range(strCopy).Copy
.Range(strPaste).PasteSpecial xlPasteValues, SkipBlanks:=True
End With
End Sub
In the case that you need to add more named ranges following your pattern, just editing str0, str1, and str2 is enough.
Let us know if this helps.
is there a way to make my code more optimized and have less named ranges in my workbook?
depends on how your data organized. But now, you can slightly simplify your code:
Sub Test()
Dim destRng As String
Dim sorceRng As String
Select Case ws0.Range("D6")
Case "BUD"
sorceRng = "CopyFormulasFT": destRng = "PasteFormulasFT"
Case "F01"
sorceRng = "CopyFormulasFTOneEleven": destRng = "PasteFormulasFTOneEleven"
Case "F02"
sorceRng = "CopyFormulasFTTwoTen": destRng = "PasteFormulasFTTwoTen"
Case "F03"
sorceRng = "CopyFormulasFTThreeNine": destRng = "PasteFormulasFTThreeNine"
Case "F04"
sorceRng = "CopyFormulasFTFourEight": destRng = "PasteFormulasFTFourEight"
Case "F05"
sorceRng = "CopyFormulasFTFiveSeven": destRng = "PasteFormulasFTFiveSeven"
Case "F06"
sorceRng = "CopyFormulasFTSixSix": destRng = "PasteFormulasFTSixSix"
Case "F07"
sorceRng = "CopyFormulasFTSevenFive": destRng = "PasteFormulasFTSevenFive"
Case "F08"
sorceRng = "CopyFormulasFTEightFour": destRng = "PasteFormulasFTEightFour"
Case "F09"
sorceRng = "CopyFormulasFTNineThree": destRng = "PasteFormulasFTNineThree"
Case "F10"
sorceRng = "CopyFormulasFTTenTwo": destRng = "PasteFormulasFTTenTwo"
Case "F11"
sorceRng = "CopyFormulasFTElevenOne": destRng = "PasteFormulasFTElevenOne"
Case Else
Exit Sub
End Select
ws1.Range(sorceRng).Copy
ws1.Range(destRng).PasteSpecial Paste:=xlPasteValues, SkipBlanks:=True
End Sub