VBA Help - Multiple Lookups and Input Boxes

OJMcGee

New Member
Joined
Jul 13, 2021
Messages
7
Office Version
  1. 365
Platform
  1. Windows
Hi,

Looking for help writing VBA that when run, will first of all ask for a name to be entered, which will be named as 'Input 1', it will then ask for a second name which will be named as 'Input 2'. It will then populate the notes on sheet 3 by looking up the references in the table to sheet 1 and then retrieving the correct note template from sheet 2.

Thanks
 

Attachments

  • Sheet 1.png
    Sheet 1.png
    14.8 KB · Views: 16
  • Sheet 2.png
    Sheet 2.png
    18.7 KB · Views: 16
  • Sheet 3.png
    Sheet 3.png
    7.8 KB · Views: 16

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
Hi OJMcGee,

Try this as a starter. Asks for an inital name and then another name, inputs 1 & 2. have added in a third box to ask for the reference as I could not figure out what is was to use to look up for the template. I've added to ask for the reference number....

VBA Code:
Sub GetTemplate()

Dim Input1 As String
Dim Input2 As String
Dim RefNum As Integer
Dim CompName As String
Dim UseTem As String
Dim Template As String
Dim Addrow As Integer

Input1 = InputBox("Type in the first name...")
Input2 = InputBox("Type in the first name...")

RefNum = InputBox("What is the reference number?")

With Sheet1
    CompName = .Columns("A:A").Find(What:=RefNum).Offset(0, 1).Value
End With

With Sheet2
    UseTem = .Columns("A:A").Find(What:=CompName).Offset(0, 1).Value
    Template = .Columns("E:E").Find(What:=UseTem).Offset(0, 1).Value
End With

With Sheet3
    If .Range("A2") <> "" Then
        Addrow = .Range("A1").End(xlDown).Offset(1, 0).Row
    Else
        Addrow = 2
    End If
    .Range("A" & Addrow).Value = RefNum
    .Range("B" & Addrow).Value = Input1 & " - " & Input2 & " " & Template
End With

MsgBox "Entry made to table..." & vbCrLf & Input1 & " - " & Input2 & " " & Template

End Sub

What I got in my test...
1725354039134.png
 
Upvote 0

Forum statistics

Threads
1,223,270
Messages
6,171,103
Members
452,379
Latest member
IainTru

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top