sdrowsick
New Member
- Joined
- Jan 17, 2020
- Messages
- 1
- Office Version
- 365
- Platform
- Windows
Hello! I'm new here, so please let me know how I can best improve for future posts...
My question is about a VBA loop in a file. I am trying to create a program that takes all the cells in a range (the range is a dynamic named range, but for this example, it's 269 rows and 37 columns), checks if each cells ends in "0" and, if the cell does end in "0", it deletes that cell and shifts the cells up. This will cut down the number of cells in the range significantly, making the next part of my program easier in terms of processing.
The VBA I have is as follows (note: "all_ids_A" is the name of the range):
The code runs, and I get a result that is not what is intended. Of the resulting cells, a plurality of them still end in "0". My initial thoughts are that the code was skipping over cells when the up-shift occurs. My other thought was that the zero in my if-statement needs to be in quotes, as it may be evaluating text against a number. I don't want to get too far down the rabbit hole, though, and I wanted to ask the experts!
Thanks, in advance, for your help.
My question is about a VBA loop in a file. I am trying to create a program that takes all the cells in a range (the range is a dynamic named range, but for this example, it's 269 rows and 37 columns), checks if each cells ends in "0" and, if the cell does end in "0", it deletes that cell and shifts the cells up. This will cut down the number of cells in the range significantly, making the next part of my program easier in terms of processing.
The VBA I have is as follows (note: "all_ids_A" is the name of the range):
VBA Code:
Sub BlankDeleter()
'Declare and set variables
Dim rng As Range
Set ws = ThisWorkbook.Sheets("Store-Item ID (A) Creation")
Set rng = Range("all_ids_A")
'For loop
For Each cell In rng
If ValueRight(cell, 1) = 0 Then
cell.Delete shift:=xlUp
End If
Next cell
End Sub
The code runs, and I get a result that is not what is intended. Of the resulting cells, a plurality of them still end in "0". My initial thoughts are that the code was skipping over cells when the up-shift occurs. My other thought was that the zero in my if-statement needs to be in quotes, as it may be evaluating text against a number. I don't want to get too far down the rabbit hole, though, and I wanted to ask the experts!
Thanks, in advance, for your help.