• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Need help with this Macro

asivaprakash

New Member
I have worked this below macro and was succesful in one out come but the others are not working


1 Delete 2861 from store

2 Delete DXJ8934MXA8484RCF959 from Processor

3 Delete + values(amt) in PLUS (cardtype)


The below code works for Delete 2861 from store.The other two need to be in the same shee and start working once option 1 finishes then option 2 should kick in then option 3.Can any one help

[pre]
Code:
Sub Loop_Delete_Macro()

Dim Counter As Integer
Dim Todelete As String
Dim NoIterations As Integer

'DEFINE VALUE TO DELETE
Todelete = 2861

'DEFINE NUMBER OF ITERATIONS (IE HOW MANY ROWS YOU HAVE IN TOTAL)
NoIterations = 15000

Counter = 0

Do While Counter < NoIterations

If ActiveCell.Value = Todelete Then

Selection.EntireRow.Delete

Else: ActiveCell.Offset(1, 0).Activate

End If
Counter = Counter + 1

Loop

End Sub
[/pre]
 
Hi, asivaprakash!


First of all welcome to Chandoo's website Excel forums. Thank you for your joining us and glad to have you here.


As a starting point I'd recommend you to read the green sticky topics at this forums main page. There you'll find general guidelines about how this site and community operates (introducing yourself, posting files, netiquette rules, and so on).


Among them you're prompted to perform searches within this site before posting, because maybe your question had been answered yet.


Feel free to play with different keywords so as to be led thru a wide variety of articles and posts, and if you don't find anything that solves your problem or guides you towards a solution, you'll always be welcome back here. Tell us what you've done, consider uploading a sample file as recommended, and somebody surely will read your post and help you.


And about questions in general...


If you haven't performed yet the search herein, try going to the topmost right zone of this page (Custom Search), type the keywords used in Tags field when creating the topic or other proper words and press Search button. You'd retrieve many links from this website, like the following one(s) -if any posted below-, maybe you find useful information and even the solution. If not please advise so as people who read it could get back to you as soon as possible.


And about this question in particular...


Firstly take care that when deleting rows you it's advisable to do it backwards, that's to say from last to first, there are cases (like this one) where it doesn't affect the process, but when walking thru a range if you do it "normally" from first to last the number of rows will be changing and you might be skipping rows to process.


One thing more: if you define a variable as string (Todelete) it's a good practice to assign it strings, even VBA has the ability to make conversions: =CStr(2861)


I tested your code and it works for 2861 and for any other value in the column of active cell. If you still have issues onsider uploading a sample file (including manual examples of desired output if applicable), it'd be very useful for those who read this and might be able to help you. Thank you. Give a look at the green sticky posts at this forums main page for uploading guidelines.


Regards!
 
Thank you for the reply.


I took you advice and uploaded the file with the conditions

https://hotfile.com/dl/224465780/66a807e/a.xlsx.html


The link is below In the mean time I will also search
 
Hi, asivaprakash!


I checked your file and:

1) It's a .xlsx file so it doesn't have any macro, it should be .xlsm, .xlsb or .xls. Despite of this I may assume that it should be used that of your first post.

2) Only 1st worksheet has data and it'a a just the skeleton, there is no data to test and try to reproduce your issue.

3) In column A there are this strings in red, are they comments, indications, required specs or what?

"1 Filter Not worked status from status Description

2 Delete 2861 from store

3 Delete DXJ8934MXA8484RCF959 from Processor

4 Delete + values(amt) in PLUS (cardtype)

5 Team will allocate to the respective associate"


Please upload a sample file but with data to perform the proper tests. And if text in red aren't comments then elaborate a bit more and explain in detail for each item what to you want to achieve.


Regards!
 
As requested the complete file.I have added the macro for one of it the reaming is where I am struggling


https://hotfile.com/dl/224531363/f32ec0c/123.xlsm.html
 
Hi, asivaprakash!


I tested your file with this change in the code:

-----

Todelete = 2861

-----

by

-----

Todelete = "Not worked"

-----

and it worked fine.


The only thing you have to consider is that before running the macro you should have selected the cell from which you want to process of the proper column. E.g., for deleting values of 2861 you should select E2, for deleting rows with values "Not Worked" you should select K2. That's because the macro uses this method to walk thru the cells:

-----

If ActiveCell.Value = Todelete Then

...

Else: ActiveCell.Offset(1, 0).Activate

-----

that's because of active cell (which is the selected one).


Regards!
 
Back
Top