Hello gurus!
I wonder if you can help me? I have the below code, however the line that I have highlight works but basically I want the VLOOKUP value (B2) formula to change consistently with whatever line the data has been put on on the summary page.....I hope I have made myself clear enough and someone can help..!
Thank you very much
Sub NewLoanbutton()
Dim WSName As String
Dim WSheet As Worksheet
NextRow = Range("A" & Rows.Count).End(xlUp).Row + 1
WSName = InputBox("Please enter then name of the person you wish to create a new loan for")
If WSName = "" Then Exit Sub
If SheetExists(WSName) Then
MsgBox ("A loan for " & WSName & " already exists. Please use the Search button to locate this page.")
Application.Goto Worksheets("Summary").Range("A1")
Exit Sub
Else
'Sheets.Add After:=Sheets(Sheets.Count)
Sheets("Template").Select
Sheets("Template").Copy After:=Worksheets(Worksheets.Count)
Range("A10").Select
Sheets("Template (2)").Select
ActiveSheet.Name = WSName
End If
'Headings
Sheets("Template").Select
Cells.Select
Selection.Copy
Sheets(WSName).Select
Cells.Select
ActiveSheet.Paste
Application.CutCopyMode = False
'New Loan box
NewLoanForm.Show
Sheets("Summary").Select
Nextrow1 = Range("B" & Rows.Count).End(xlUp).Row + 1
Range("B" & Nextrow1).Value = WSName
Range("D" & Nextrow1).Formula = "=SUMIF( '" & WSName & "'!B:B, ""<2011"", '" & WSName & "'!G:G)"
Range("E" & Nextrow1).Formula = "=SUMIF( '" & WSName & "'!B:B, ""=2011"", '" & WSName & "'!G:G)"
Range("F" & Nextrow1).Formula = "=SUMIF( '" & WSName & "'!B:B, ""=2012"", '" & WSName & "'!G:G)"
Range("G" & Nextrow1).Formula = "=SUMIF( '" & WSName & "'!B:B, ""=2013"", '" & WSName & "'!G:G)"
Range("A" & Nextrow1).Formula = "=VLOOKUP(B12,Information!A:C,3,FALSE)"
End Sub
I wonder if you can help me? I have the below code, however the line that I have highlight works but basically I want the VLOOKUP value (B2) formula to change consistently with whatever line the data has been put on on the summary page.....I hope I have made myself clear enough and someone can help..!
Thank you very much
Sub NewLoanbutton()
Dim WSName As String
Dim WSheet As Worksheet
NextRow = Range("A" & Rows.Count).End(xlUp).Row + 1
WSName = InputBox("Please enter then name of the person you wish to create a new loan for")
If WSName = "" Then Exit Sub
If SheetExists(WSName) Then
MsgBox ("A loan for " & WSName & " already exists. Please use the Search button to locate this page.")
Application.Goto Worksheets("Summary").Range("A1")
Exit Sub
Else
'Sheets.Add After:=Sheets(Sheets.Count)
Sheets("Template").Select
Sheets("Template").Copy After:=Worksheets(Worksheets.Count)
Range("A10").Select
Sheets("Template (2)").Select
ActiveSheet.Name = WSName
End If
'Headings
Sheets("Template").Select
Cells.Select
Selection.Copy
Sheets(WSName).Select
Cells.Select
ActiveSheet.Paste
Application.CutCopyMode = False
'New Loan box
NewLoanForm.Show
Sheets("Summary").Select
Nextrow1 = Range("B" & Rows.Count).End(xlUp).Row + 1
Range("B" & Nextrow1).Value = WSName
Range("D" & Nextrow1).Formula = "=SUMIF( '" & WSName & "'!B:B, ""<2011"", '" & WSName & "'!G:G)"
Range("E" & Nextrow1).Formula = "=SUMIF( '" & WSName & "'!B:B, ""=2011"", '" & WSName & "'!G:G)"
Range("F" & Nextrow1).Formula = "=SUMIF( '" & WSName & "'!B:B, ""=2012"", '" & WSName & "'!G:G)"
Range("G" & Nextrow1).Formula = "=SUMIF( '" & WSName & "'!B:B, ""=2013"", '" & WSName & "'!G:G)"
Range("A" & Nextrow1).Formula = "=VLOOKUP(B12,Information!A:C,3,FALSE)"
End Sub