help with looping something for the entire column

bananacuriel

New Member
Joined
Feb 19, 2018
Messages
2
Ive been having troubles looping mi script into the entire column. it looks like this

Sub if_veracruz()


Dim score1 As Integer, score2 As Integer, result As String


score1 = Range("F2").Select


score2 = Range("h2").Select


If score1 = 30 And score2 <= 5 Or score2 = 8 Or score2 = 10 Then


result = "Veracruz Norte"


Else


result = "Veracruz Sur"


End If


Range("G2").Value = result




i thought i could add something like this

Dim x As Integer

Application.ScreenUpdating = False


' Set numrows = number of rows of data.


NumRows = Range("g2", Range("g2").End(xlDown)).Rows.Count


' Select cell g2.


Range("g2").Select


' Establish "For" loop to loop "numrows" number of times.


For x = 1 To NumRows


'code here


' Selects cell down 1 row from active cell.


ActiveCell.Offset(1, 0).Select


Next


Application.ScreenUpdating = True


End Sub



but when trying to join them it only appears error...please help
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Hi & welcome to MrExcel
Is this what you want?
Code:
Sub if_veracruz()

   Dim score1 As Integer, score2 As Integer
   Dim Cl As Range
   
   For Each Cl In Range("F2", Range("F" & Rows.Count).End(xlUp))
   
      score1 = Cl.Value
      score2 = Cl.Offset(, 2).Value
      
      If score1 = 30 And score2 <= 5 Or score2 = 8 Or score2 = 10 Then
         Cl.Offset(, 1).Value = "Veracruz Norte"
      Else
         Cl.Offset(, 1).Value = "Veracruz Sur"
      End If
   Next Cl

End Sub
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0
or:

Code:
Sub blablabla()
LR = Range("F" & Rows.Count).End(xlUp).Row
SR = Range("F1:H" & LR)
For i = 2 To UBound(SR)
    If SR(i, 1) = 30 And SR(i, 3) <= 5 Or SR(i, 3) = 8 Or SR(i, 3) = 10 Then
         SR(i, 2) = "Veracruz Norte"
    Else
         SR(i, 2) = "Veracruz Sur"
    End If
Next
Range("F1:H" & UBound(SR)) = SR
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,912
Members
452,366
Latest member
TePunaBloke

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