Good morning,
I have created a userform for people to use to generate a unique reference for a campaign. I use text boxes, option buttons and combo boxes to get the data which is then input into a worksheet and then use a vlookup formula in a worksheet to create the reference. The reference has a unique identifier in it (a countif) so I need this to overwrite with values so that the countif doesn't keep totaling up.
I'm thinking now it would be better if I wrote the vlookup formula in VBA code, so that it would be hard-coded into the worksheet and I don't have to write a copy and paste loop into the code, but I'm having trouble writing this. This is the code I've written as a test so far, but it doesn't seem to like it:
Dim ActDate As String
Dim Name As String
Dim ActName As String
Dim Channel As String
Dim Campaign As String
Dim Product As String
Dim Audience As String
Dim YourCode As Long
Dim ActivityDate As String
Dim ActivityChannel As String
Set ActDate = ComboBox1.Text
Set Name = TextBox2.Text
Set ActName = TextBox3.Text
Set Channel = ComboBox2.Text
Set Campaign = ComboBox3.Text
ActivityDate = ActDate
ActivityChannel = Channel
YourCode = Application.WorksheetFunction.VLookup(ActivityDate, Sheets("Reference Tables").Range("O:P"), 2, False) & "-" & Application.WorksheetFunction.VLookup(Channel, Sheets("Reference Tables").Range("H:J"), 2, False)
MsgBox ("Your Code ") & YourCode
The Countif part isn't in this code yet as I just wanted to make sure it worked first, but I would need a vlookup to create the reference needs to include ActivityDate, Channel, Campaign, Product and Audience and then a Countif for how many times an activity name appears in a column.
I'm not sure where I'm going wrong with this. I have another vlookup that seems to work fine, but for some reason this one doesn't. I'm using a message box so that I can make sure it works first but then it would need to move down a row.
Any and all help always appreciated. Let me know if you need any more detail.
I have created a userform for people to use to generate a unique reference for a campaign. I use text boxes, option buttons and combo boxes to get the data which is then input into a worksheet and then use a vlookup formula in a worksheet to create the reference. The reference has a unique identifier in it (a countif) so I need this to overwrite with values so that the countif doesn't keep totaling up.
I'm thinking now it would be better if I wrote the vlookup formula in VBA code, so that it would be hard-coded into the worksheet and I don't have to write a copy and paste loop into the code, but I'm having trouble writing this. This is the code I've written as a test so far, but it doesn't seem to like it:
Dim ActDate As String
Dim Name As String
Dim ActName As String
Dim Channel As String
Dim Campaign As String
Dim Product As String
Dim Audience As String
Dim YourCode As Long
Dim ActivityDate As String
Dim ActivityChannel As String
Set ActDate = ComboBox1.Text
Set Name = TextBox2.Text
Set ActName = TextBox3.Text
Set Channel = ComboBox2.Text
Set Campaign = ComboBox3.Text
ActivityDate = ActDate
ActivityChannel = Channel
YourCode = Application.WorksheetFunction.VLookup(ActivityDate, Sheets("Reference Tables").Range("O:P"), 2, False) & "-" & Application.WorksheetFunction.VLookup(Channel, Sheets("Reference Tables").Range("H:J"), 2, False)
MsgBox ("Your Code ") & YourCode
The Countif part isn't in this code yet as I just wanted to make sure it worked first, but I would need a vlookup to create the reference needs to include ActivityDate, Channel, Campaign, Product and Audience and then a Countif for how many times an activity name appears in a column.
I'm not sure where I'm going wrong with this. I have another vlookup that seems to work fine, but for some reason this one doesn't. I'm using a message box so that I can make sure it works first but then it would need to move down a row.
Any and all help always appreciated. Let me know if you need any more detail.