Hi ! I am relatively new to coding in VBA and started building a program in which I want to go through a Worksheet and basically concatenate the values of 2 columns (A and D) and the value of column S depending on its value. After this is created I want to check in another worksheet if this unique value already exists, and if it does not add the row of information with its unique name.
Let me use my example so you better understand what I am trying to accomplish. I have one worksheet names RecurrentJobs which has the JobNames (column A), Account #'s (column D), and frequency per job (ex. daily, weekly, monthly...) (column S). The other columns have information but I do not need them at the moment. I want my macro to concatenate the JobNames + Account #, and loop through the frequency and perform a formula dependent on the value.
After this is performed I want to check these names with the names in column A on my other worksheet called MasterJobs. If the name already exists then nothing happens, but if the name does not exist then I want to add it to the list and copy information from entire row to the worksheet.
Here is what I have until now for the creation of the unique names (concatenate):
Sub FreqCalc()
'macro to loop through the recurrent jobs and create new jobs on master job trail based on their specified frequency
Dim RecurrentJobTrail As Worksheet
Dim NameRange As Long
Dim Frequency As Range
Dim SubAccount As Range
Dim CompleteUniqueName As String
Set RecurrentJobTrail = Worksheets("Recurrent Job Trail")
Set SubAccount = RecurrentJobTrail.Range("D2:D15000")
Set Frequency = RecurrentJobTrail.Range("S2:S15000")
Set NameRange = RecurrentJobTrail.Cells(Rows.Count, 1).End(xlUp).Row
'Check the recurrent jobs list to create unique values depending on their specified frequency
For Each RecJobCell In NameRange
CompleteUniqueName = RecJobCell & "-" & SubAccount & "-"
'frecuencia diaria
If Frequency = "Diario" Then
CompleteUniqueName = CompleteUniqueName & Format(Now(), "dd/mmm/yyyy")
'frecuencia semanal
ElseIf Frequency = "Semanal" Then
CompleteUniqueName = CompleteUniqueName & "Week of " & (Date - Weekday(Date, vbMonday) + 1)
'frecuencia mensual
ElseIf Frequency = "Mensual" Then
CompleteUniqueName = CompleteUniqueName & Format(Now(), "mmm/yyyy")
'frecuencia trimestral
ElseIf Frequency = "Trimestral" Then
CompleteUniqueName = CompleteUniqueName & "Trimester starting " & Format(Now(), "yyyy")
'frecuencia anual
ElseIf Frequency = "Anual" Then
CompleteUniqueName = CompleteUniqueName & Format(Now(), "yyyy")
End If
Next RecJobCell
End Sub
Let me use my example so you better understand what I am trying to accomplish. I have one worksheet names RecurrentJobs which has the JobNames (column A), Account #'s (column D), and frequency per job (ex. daily, weekly, monthly...) (column S). The other columns have information but I do not need them at the moment. I want my macro to concatenate the JobNames + Account #, and loop through the frequency and perform a formula dependent on the value.
After this is performed I want to check these names with the names in column A on my other worksheet called MasterJobs. If the name already exists then nothing happens, but if the name does not exist then I want to add it to the list and copy information from entire row to the worksheet.
Here is what I have until now for the creation of the unique names (concatenate):
Sub FreqCalc()
'macro to loop through the recurrent jobs and create new jobs on master job trail based on their specified frequency
Dim RecurrentJobTrail As Worksheet
Dim NameRange As Long
Dim Frequency As Range
Dim SubAccount As Range
Dim CompleteUniqueName As String
Set RecurrentJobTrail = Worksheets("Recurrent Job Trail")
Set SubAccount = RecurrentJobTrail.Range("D2:D15000")
Set Frequency = RecurrentJobTrail.Range("S2:S15000")
Set NameRange = RecurrentJobTrail.Cells(Rows.Count, 1).End(xlUp).Row
'Check the recurrent jobs list to create unique values depending on their specified frequency
For Each RecJobCell In NameRange
CompleteUniqueName = RecJobCell & "-" & SubAccount & "-"
'frecuencia diaria
If Frequency = "Diario" Then
CompleteUniqueName = CompleteUniqueName & Format(Now(), "dd/mmm/yyyy")
'frecuencia semanal
ElseIf Frequency = "Semanal" Then
CompleteUniqueName = CompleteUniqueName & "Week of " & (Date - Weekday(Date, vbMonday) + 1)
'frecuencia mensual
ElseIf Frequency = "Mensual" Then
CompleteUniqueName = CompleteUniqueName & Format(Now(), "mmm/yyyy")
'frecuencia trimestral
ElseIf Frequency = "Trimestral" Then
CompleteUniqueName = CompleteUniqueName & "Trimester starting " & Format(Now(), "yyyy")
'frecuencia anual
ElseIf Frequency = "Anual" Then
CompleteUniqueName = CompleteUniqueName & Format(Now(), "yyyy")
End If
Next RecJobCell
End Sub