I am using VBA in Excel to take information from a log (sheet1) and create a new form based off of a template. The information is not static, in other words I am unable to use .FormulaR1C1 to define cell locations from which to populate the form. As I am a novice, I used Record Macro to help start the structure for this macro, but am now having a hard time converting the .FormulaR1C1 into something more flexible. As can be seen in the following code, I have created various Dim to allow for the variables, but I'm not sure this will really get me to the end result I am looking for.
I have successfully created the new spreadsheet and named it, but now I do not know how to identify the new sheet and the selected cells and create a formula to make them equal cells from sheet1 that are located wherever my cursor happens to be.
The end result is that once the form is created, I would like the cells identified in the code above to have a formula in them such that any changes to the log (sheet1) would effect the appropriate changes to the newly created sheet.
Thank you in advance for any help.
I have successfully created the new spreadsheet and named it, but now I do not know how to identify the new sheet and the selected cells and create a formula to make them equal cells from sheet1 that are located wherever my cursor happens to be.
Code:
Sub CreateRFI()
'
' CreateRFI Macro
' Creates an RFI based off of infromation in this sheet.
'
'
Dim i As Integer
i = Range("A" & ActiveCell.Row).Value
Sheet_name_to_create = "RFI " & i
Dim submitted, due As Date
submitted = Range("C" & ActiveCell.Row).Value
due = Range("D" & ActiveCell.Row).Value
Dim description As String
description = Range("B" & ActiveCell.Row).Value
For rep = 1 To (Worksheets.Count)
If LCase(Sheets(rep).Name) = LCase(Sheet_name_to_create) Then
MsgBox "This sheet already exists. Please create new RFI or delete existing sheet."
Exit Sub
End If
Next
Sheets("RFI Log").Select
Sheets("RFI Template").Visible = True
Sheets("RFI Template").Select
Range("A1:J46").Select
Range("J46").Activate
Selection.Copy
Sheets.Add After:=Sheets(Sheets.Count)
Selection.PasteSpecial Paste:=xlPasteColumnWidths, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
ActiveSheet.Paste
Sheets(ActiveSheet.Name).Select
Sheets(ActiveSheet.Name).Name = Sheet_name_to_create
[COLOR=#b22222]Range("H8:I9").Select
ActiveCell.FormulaR1C1 = "='RFI Log'!R[117]C[-7]"
Range("G10:H10").Select
ActiveCell.FormulaR1C1 = "='RFI Log'!R[115]C[-4]"
Range("B17").Select
ActiveCell.FormulaR1C1 = "='RFI Log'!R[108]C"
Range("H17").Select
ActiveCell.FormulaR1C1 = "='RFI Log'!R[108]C[-4]"[/COLOR]
Range("H18").Select
Sheets("RFI Template").Select
ActiveWindow.SelectedSheets.Visible = False
End Sub
The end result is that once the form is created, I would like the cells identified in the code above to have a formula in them such that any changes to the log (sheet1) would effect the appropriate changes to the newly created sheet.
Thank you in advance for any help.