Is there a way to code a between macro?

seriouslystuck

Board Regular
Joined
Sep 24, 2009
Messages
97
Hi

I want to loop through column F and check each cell value if it is between E1 and H1 and if it is then put an x in column X. Im having real problems with this. I have found some code online and tried to modify it with little sucess. Any advice would be great.

Thanks
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Possibly

Code:
Sub test()
Dim LR As Long, i As Long
LR = Range("F" & Rows.Count).End(xlUp).Row
For i = 1 To LR
    With Range("F" & i)
        If .Value >= Range("E1").Value And .Value <= Range("H1").Value Then .Offset(, 18).Value = "X"
    End With
Next i
End Sub
 
Upvote 0
Peter

This works perfect!! Just while you are here could you please tell me how to run until last row instead of do until

Range("a1").Select
Do Until Selection.Value = ""
If Not Selection.Value = "1" Then
Selection.EntireRow.Delete
Else
Selection.Offset(1, 0).Select
End If
Loop
 
Upvote 0
Try

Code:
Sub atest()
Dim LR As Long, i As Long
LR = Range("A" & Rows.Count).End(xlUp).Row
For i = LR To 1 Step -1
    With Range("A" & i)
        If .Value <> "1" Then .EntireRow.Delete
    End With
Next i
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,545
Messages
6,179,432
Members
452,915
Latest member
hannnahheileen

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