lundi 22 janvier 2018

Tables and loops VBA

I am new to coding and have written some code to do some calculations within a table and fill in columns. I have it working for the first row within the table but I am having some trouble figuring out how to loop it so that it completes the calculations for every row within the table. Any help and advice would be greatly appreciated!

Sub CommandButton1_Click()

Dim Reach As Long
Dim Result As Integer

Reach = Range("T2").Value

If Reach >= 100000 Then
Result = 5
ElseIf Reach < 100000 And Reach >= 50000 Then
Result = 3
ElseIf Reach < 50000 And Reach >= 10000 Then
Result = 2
ElseIf Reach < 10000 Then
Result = 1
End If

Range("V2").Value = Result



Dim Headline As String, Exclusive As String
Dim Result1 As Integer

Headline = Range("L2").Value
Exclusive = Range("M2").Value

If Headline = "Yes" Then
Result1 = 5
ElseIf Headline = "No" And Exclusive = Yes Then
Result1 = 3
ElseIf Headline = "No" And Exclusive = "No" Then
Result1 = 1
End If

Range("U2").Value = Result1




Dim Sentiment As String
Dim Result2 As Integer

Sentiment = Range("K2").Value

If Sentiment = "Very Positive" Then
Result2 = 2
ElseIf Sentiment = "Very Negative" Then
Result2 = 2
Else: Result2 = 1
End If

Range("W2").Value = Result2



End Sub

Aucun commentaire:

Enregistrer un commentaire