Basic question regarding cell.value

ExcelFL

New Member
Joined
May 15, 2014
Messages
10
I am trying to have the value in cell A1 which is dal be the basis to clear the values in cells a5 to a500. The below formula does not work for the loop function; help much appreciated.
-------------
Option Explicit

Sub test()

Dim x As Variant
Dim y As Long
x = Cells(1, 1).Value
MsgBox x
y = 5

For y = y To 500 Step 1
If Cells(y, 1).Value = x Then
Cells(y, 1).Clear
End If
Next y

End Sub
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Try looping backwards

Rich (BB code):
Sub test()

Dim x As Variant
Dim y As Long
x = Cells(1, 1).Value
MsgBox x
y = 5

For y = 500 To y Step -1
If Cells(y, 1).Value = x Then
Cells(y, 1).Clear
End If
Next y

End Sub
 
Upvote 0
It could be an issue with Case Sensitiveness (VBA is case sensitive)
So if x = DAL, but the Cells(y,1) = dal, then it won't be considered a match.

Try

If UCase(Cells(y, 1).Value) = UCase(x) Then
 
Upvote 0
Also, if you're comparing numbers there may be rounding, "coersion", and/or machine storage involved. For instance, if your values in rows 5 to 500 are displayed to 2 decimals, but are results of calculations with more stored digits, they won't match a number entered in cell(1,1) even if they look like they should.
 
Upvote 0

Forum statistics

Threads
1,216,119
Messages
6,128,946
Members
449,480
Latest member
yesitisasport

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