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 6174509
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T23:45:56+00:00 2026-05-23T23:45:56+00:00

I have this macro: Sub StringChecker() Dim string_arr() As Variant Dim k As Integer

  • 0

I have this macro:

Sub StringChecker()

Dim string_arr() As Variant
Dim k As Integer

Dim c As Range
Set c = ActiveSheet.[A1]

end_string = Array(" &", _
            " TR", _
            " SR", _
            " DEFEN")

substring = Array(" SR ", _
            " JR ")

Do While c <> "End Loop"

   c.Offset(0, 1) = c

   For k = 0 To UBound(end_string)

      If Right(c, Len(end_string(k))) = end_string(k) Then
          cleaner_string = Mid(c, 1, Len(c) - Len(end_string(k)))

      End If


   Next k
   clean_string = cleaner_string
   For l = 0 To UBound(substring)
        clean_string = Replace(clean_string, substring(l), " ")
    Next l

    If clean_string = "" Then
            clean_string = c
    End If
    c.Offset(0, 1) = clean_string
   Set c = c.Offset(1, 0)

Loop



End Sub

THe problem is when it finds a character in the array that matches the current string iteration, it ends up copying that string over to every cell iteration thereafter.

Here’s an example of output:

 Owner1                 Owner1
BURDINES 1225 LLC           BURDINES 1225 LLC
MIAMI-DADE COUNTY           MIAMI-DADE COUNTY
RELATED GROUP OF FLORIDA &  RELATED GROUP OF FLORIDA
BURDINES 1225 LLC           RELATED GROUP OF FLORIDA
CITY OF MIAMI DEPT OF P & D RELATED GROUP OF FLORIDA
MIAMI-DADE COUNTY           RELATED GROUP OF FLORIDA
FEC R R CO                  RELATED GROUP OF FLORIDA
BDG 200 SOUTH MIAMI AVE LLC RELATED GROUP OF FLORIDA
STATE OF FLORIDA DOT    RELATED GROUP OF FLORIDA

It copies over RELATED GROUP OF FLORIDA during each iteration after it finds that that cell ended with an & which was part of our end_string array. Same thing may be occuring with the substring array. I looked at this closely, and I am not sure why this behavior occurs. It’s supposed to be removing all characters in the cell that were found in both the end_string and substring array and copying them to new cell. If the indexes from the array were not found in the string, then it just copies over original string to column B. Also I use the string “End Loop” because I cannot check for an empty string since there may be 4 or 5 empty cells in column a before there is another cell with content, so I dont want the iteration to just stop just because one cell was empty.

Thanks for response

  • 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-05-23T23:45:57+00:00Added an answer on May 23, 2026 at 11:45 pm

    You need to wipe cleanerstring at the beginning of every pass through the loop. Otherwise, it retains its value from the last time through, and if the cell the doesn’t meet the criteria for cleanerstring to be edited, cleanstring becomes cleanerstring (which was the last iteration’s clearnerstring), so cleanstring will never be “”. Does that make sense?

    EDIT

    To make this clearer:

    If the cell you’re looking at doesn’t meet the criteria for editing, cleanerstring is never set to anything new. So if was given a value the last time through, it still has that value. Thus, when you say

    cleanstring = cleanerstring
    

    if cleanerstring was never set to anything new, cleanstring now has the cleanerstring value from the last time through. Cleanstring now gets cleaned up in your formatting code, and when you then check if

    cleanstring = ""
    

    you evaluate to false, because cleanstring is last time’s cleanerstring, cleaned-up again. Thus cleanstring is not reset to c, so

    c.Offset(0, 1) = clean_string
    

    sets the cell to the cleaned-up text from last time.

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

Sidebar

Related Questions

I have seen this macro defined before but never really knew its purpose. Can
I have a macro that looks like this: #define coutError if (VERBOSITY_SETTING >= VERBOSITY_ERROR)
I have the following macro: %macro export_set_excel(data,tabname); PROC EXPORT DATA= &data. OUTFILE= &results. DBMS=EXCEL
I have a RDK-IDM from Luminary Micro . This board has a 32-bit ARM®
I have this code in jQuery, that I want to reimplement with the prototype
I have this idea for a free backup application. The largest problem I need
I have this gigantic ugly string: J0000000: Transaction A0001401 started on 8/22/2008 9:49:29 AM
I have this line in a javascript block in a page: res = foo('<%=
I have this setup where in my development copy I can commit changes on
I have this string 'john smith~123 Street~Apt 4~New York~NY~12345' Using JavaScript, what is the

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.