VBA help

pauleverton

New Member
Joined
Feb 8, 2014
Messages
23
Hello,

Sorry for what is probably a really simple question but can't seem to find the answer to what I'm trying to do, although probably misunderstood what I was looking at (very new to VBA)!

All I'm trying to do is loop the below text so that it continues for the whole spreadsheet where there is data in column B

Dim score As Integer, result As String
score = Range("B2").Value
If score >= 6 Then result = "this is great"


Range("H2").Value = result
Selection.Offset(1, 0).Select

I don't know if I need to adjust the range or if it needs looping down the column, bit confused.

If anyone can help that would be much appreciated.

Paul
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Try this:

Code:
Sub Score()

Dim LastRow As Integer
Dim Counter As Integer

LastRow = Range("B65000").End(xlUp).Row

For Counter = 2 to LastRow

If Range("B" & Counter).Value >= 6 Then Range("H" & Counter) = "This is great"

Next Counter

End Sub
 
Upvote 0
Try this:

Code:
Sub Score()

Dim LastRow As Integer
Dim Counter As Integer

LastRow = Range("B65000").End(xlUp).Row

For Counter = 2 to LastRow

If Range("B" & Counter).Value >= 6 Then Range("H" & Counter) = "This is great"

Next Counter

End Sub
Thank you, that's worked perfectly!!!
 
Upvote 0

Forum statistics

Threads
1,215,091
Messages
6,123,062
Members
449,090
Latest member
fragment

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