Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7863757
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T23:35:03+00:00 2026-06-02T23:35:03+00:00

I’m looking for an algorithm for which I do not have the VBA knowledge

  • 0

I’m looking for an algorithm for which I do not have the VBA knowledge to script myself. So I’m stuck. It isn’t through lack of effort trying because I have given it a go (plus, this bit of code is the last remaining piece of my bigger VBA code) I simply lack the knowledge/experience/skill…

Basically, I have an Excel file. In this file is a sheet, “sheet1”. Sheet1 contains many rows of data. The number of rows contained in sheet1 can vary from 1 to n. Sometimes, I may have 50 while other times I may have 30, etc. What is consistent is the layout of the book, i.e. I have codes in column A which identify a product in my database.

What I want to do is this:

1. Scan the sheet for empty rows (due to the way the workbook is generated, I sometimes have blank rows) and remove them. These blank rows are sometimes in-between rows with data while at other times may be trailing at the end of the sheet.

2. After removing the blank rows find the last used row. Store that to a variable. I have found this piece of code useful for doing that:

mylastrow = myBook.Sheets("Results").Cells.Find(what:="*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row

3. Starting from the row determined in (2), I want to take the product code in A(x where x = mylastrow) and find any other occurrences of it (in column A). If any are found, delete that entire row corresponding to it. Importantly, this loop must go in reverse. For example let’s say mylastrow = 40, the loop will need to begin at A40 and on the next iteration do A39 (or 38 if a row has been removed?). This is because with any of the product numbers the corresponding data in the row contains more data further down the column (because of the way the sheet was generated). Essentially the entry closest to the last row is the most recent.

Hopefully I’ve been able to explain the situ properly. But if not and you’re willing to take the challenge (my burden?) off me I would be very grateful.

QF

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T23:35:04+00:00Added an answer on June 2, 2026 at 11:35 pm

    The only way to develop that knowledge and skill is to get in there and code! I’m sure someone may come in and write you the entire procedure, but in the meantime these resources should give you the tools to do it yourself.

    First, check out the method here to delete blank rows. It relies on “Selection” for the range, so you can either manually select all the cells of the sheet, then run the macro, or replace it with the following:

    Dim r as range
    set r = Sheet1.Cells 'now use r instead of Selection
    

    OR (even better) use your code for finding the last used row and set the range from row 1 to “mylastrow”.

    Next, beginning from “mylastrow”, start adding the values in Column A to a Dictionary object (example here). You can use a row counter to decrement from “mylastrow” to 1. Here’s an example of how it would work. The key is assumed to be in the 1st column (“A”).

    Dim dict As Object
    Dim rowCount As Long
    Dim strVal As String
    
    Set dict = CreateObject("Scripting.Dictionary")
    
    rowCount = Sheet1.Range("A1").CurrentRegion.Rows.Count
    
    Do While rowCount > 1
      strVal = Sheet1.Cells(rowCount, 1).Value2
    
      If dict.exists(strVal) Then
        Sheet1.Rows(rowCount).EntireRow.Delete
      Else
        dict.Add strVal, 0
      End If
    
      rowCount = rowCount - 1
    Loop
    
    Set dict = Nothing
    

    Before:
    Before
    After:
    After

    Note that the 1st row hasn’t been touched since we stopped when rowCount is 1 (assumes there’s a header).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a text area in my form which accepts all possible characters from
I am trying to loop through a bunch of documents I have to put
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.