I have created this macro and having a small issue. I am very new to this VBA and did this with experts’ guides by googling it. I am creating an excel form for a work purpose at work. The Excel form has 7 sheets and each have named tables with different data.
- 1st sheet is the editable form, which retrieves data from the tables in the different sheets. This is the only visible sheet, and other sheets are protected and hidden,
- 1st sheet has hidden rows and columns those have logical formulas that assist me to retrieve my data from the other tables, so cells with formulas (mostly-vlookup, index, match, if, or) are in those rows and columns.
- I want the user to edit on the retrieved data, which is kind of suggestion to the user for to use it as-is or edit on it if required.
- I cannot write vlookup or loop kind of events, so I created below macro that allows me to retrieve the value of the formula as a text (not editable) in different cell, then retrieve that text to another merged and named cell as editable text.
- This macro works fine, but when I add more and more data into the Excel and add other macros, then it is quit slow.
Is it possible to this and make it function faster?
This macro applies to Sheet 1.
Private Sub Worksheet_Change(ByVal Target As Range)
'Value as text - kind of copy+pastespecial
If Range("F17").Value <> Range("E17").Text Then
Range("F17").FormulaR1C1 = Range("E17")
Range("func_R").FormulaR1C1 = Range("F17")
'func_R and other cells below with "_R" are my merged and main cells that users will see. E17 has a vlookup formula that retrieve data from a table in Sheet 2, with this macro I copy and pastpecial the formula in E17 in F17 as a text. Then to make it editable text I copy and paste it into the merged cell with "_R".Texts in cells with "_R" come from same table in sheet 2.
ElseIf Range("F18").Value <> Range("E18").Text Then
Range("F18").FormulaR1C1 = Range("E18")
Range("job_R").FormulaR1C1 = Range("F18")
ElseIf Range("F20").Value <> Range("E20").Value Then
Range("F20").FormulaR1C1 = Range("E20")
Range("purp_R").FormulaR1C1 = Range("F20")
ElseIf Range("F22").Value <> Range("E22").Value Then
Range("F22").FormulaR1C1 = Range("E22")
Range("duty_R").FormulaR1C1 = Range("F22")
ElseIf Range("F25").Value <> Range("E25").Value Then
Range("F25").FormulaR1C1 = Range("E25")
Range("ikey_R").FormulaR1C1 = Range("F25")
ElseIf Range("F26").Value <> Range("E26").Value Then
Range("F26").FormulaR1C1 = Range("E26")
Range("ekey_R").FormulaR1C1 = Range("F26")
ElseIf Range("F28").Value <> Range("E28").Value Then
Range("F28").FormulaR1C1 = Range("E28")
Range("iimp_R").FormulaR1C1 = Range("F28")
ElseIf Range("F29").Value <> Range("E29").Value Then
Range("F29").FormulaR1C1 = Range("E29")
Range("eimp_R").FormulaR1C1 = Range("F29")
'Generel requirement - it is basicly same as above, but data comes from different table in Sheet 3.
ElseIf Range("F31").Value <> Range("E31").Value Then
Range("F31").FormulaR1C1 = Range("E31")
Range("req_1").FormulaR1C1 = Range("F31")
ElseIf Range("F32").Value <> Range("E32").Value Then
Range("F32").FormulaR1C1 = Range("E32")
Range("req_2").FormulaR1C1 = Range("F32")
ElseIf Range("F33").Value <> Range("E33").Value Then
Range("F33").FormulaR1C1 = Range("E33")
Range("req_3").FormulaR1C1 = Range("F33")
ElseIf Range("F34").Value <> Range("E34").Value Then
Range("F34").FormulaR1C1 = Range("E34")
Range("req_4").FormulaR1C1 = Range("F34")
ElseIf Range("F35").Value <> Range("E35").Value Then
Range("F35").FormulaR1C1 = Range("E35")
Range("req_5").FormulaR1C1 = Range("F35")
End If
End Sub