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

  • SEARCH
  • Home
  • 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 7704783
In Process

The Archive Base Latest Questions

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

I currently run a macro to compare the most recent sheet of data to

  • 0

I currently run a macro to compare the most recent sheet of data to the report immediately prior and highlight changes. It works fine on its own. Now, however, we would like to be able to compare selected sheets from any time period. My idea was to pop up a simple userform with two textboxes that the user can use to specify which two reports he wants to compare. I am quite lost though with the idea of trying to declare public variables; what I’ve got atm is:

Option Explicit
Public shtNew As String, shtOld As String, _
TextBox1 As TextBox, TextBox2 As TextBox

Sub SComparison()

    Const ID_COL As Integer = 31 'ID is in this column
    Const NUM_COLS As Integer = 31 'how many columns are being compared?

    Dim rwNew As Range, rwOld As Range, f As Range
    Dim X As Integer, Id

    shtNew = CSManager.TextBox1
    shtOld = CSManager.TextBox2

    'Row location of the first employee on "CurrentMaster" sheet
    Set rwNew = shtNew.Rows(5)

    Do While rwNew.Cells(ID_COL).Value <> ""

        Id = rwNew.Cells(ID_COL).Value
        Set f = shtOld.UsedRange.Columns(ID_COL).Find(Id, , xlValues, xlWhole)

        If Not f Is Nothing Then

            Set rwOld = f.EntireRow

            For X = 1 To NUM_COLS
                If rwNew.Cells(X).Value <> rwOld.Cells(X).Value Then
                    rwNew.Cells(X).Interior.Color = vbYellow
                    rwNew.Cells(33) = "UPDATE"
                Else
                    rwNew.Cells(X).Interior.ColorIndex = xlNone
                End If
            Next X

        End If

        Set rwNew = rwNew.Offset(1, 0) 'next row to compare

        Loop

        Call SUpdates
End Sub
  • 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-31T23:45:32+00:00Added an answer on May 31, 2026 at 11:45 pm

    My Suggestion would be to use Comboboxes instead of TextBoxes. Create a userform with two command buttons and two comboboxes and populate the comboboxes in the UserForm_Initialize() event using this code.

    Private Sub UserForm_Initialize()
        Dim ws As Worksheet
    
        For Each ws In ActiveWorkbook.Sheets
            ComboBox1.AddItem ws.Name: ComboBox2.AddItem ws.Name
        Next
    End Sub
    

    And then use this code in the OK button to do the comparison.

    Private Sub CommandButton1_Click()
        Dim shtNew As Worksheet, shtOld As Worksheet
    
        If ComboBox1.ListIndex = -1 Then
            MsgBox "Please select the first sheet"
            Exit Sub
        End If
    
        If ComboBox2.ListIndex = -1 Then
            MsgBox "Please select the Second sheet"
            Exit Sub
        End If
    
        Set shtNew = Sheets(ComboBox1.Value)
        Set shtOld = Sheets(ComboBox2.Value)
    
        '~~> REST OF THE CODE HERE NOW TO WORK WITH THE ABOVE SHEETS
    End Sub
    
    Private Sub CommandButton2_Click()
        Unload Me
    End Sub
    

    HTH

    Sid

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

Sidebar

Related Questions

I currently run Visual Studio 2008 SP1 connecting to Team Foundation Server. I want
I currently run an Rails app on a single VPS with it's own MySQL
I've currently run into a performance problem when updating properties on lots of dom
Are there alternatives to gitosis that are easier to use? I currently run gitosis
Currently we run our web applications on a thin client browser IE 6 and
Currently I run a web app that heavily relies on short URLs that link
I'm currently trying to run a LINQ query over a MS SQL database. This
I'm currently trying to run a certain procedure (sql 2005) in VB6, passing some
i am currently trying to run a web crawler through the terminal. it compiles
I've got a Macro that I run that writes a copyright header to my

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.