Help with data comparison between two sheets

greatparthi

New Member
Joined
Feb 14, 2016
Messages
2
Before I begin, I should tell you all that I am a complete noob to excel and VBA macro.
I am trying to compare two excel sheet data by using EXACT formula. sometimes the data ranges to 50 columns and 10000+ rows, So I am using a VBA macro to define the range and applying the formula. perhaps the following code will explain better,

I was manually inputting the range values to insert formula and apply the formatting. Now I would like to avail some help on applying the formula dynamically based on the Sheet1 cell ranges.
i.e., if Sheet1 contains data till A1:AU5000, then in Sheet 3 When I run this VBA I want formula to be applied on that range.

Sub FormulaInsertion()
'macro to insert formula
Range("G1:L101").Formula = "=EXACT(Sheet1!A1, Sheet2!A1)"
Call FormattingValues
End Sub
Sub FormattingValues()
'
' Formatting Macro
'
Range("G1:L101").Select
Selection.FormatConditions.Add Type:=xlTextString, String:="FALSE", _
TextOperator:=xlContains
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Font
.Color = -16383844
.TintAndShade = 0
End With
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = 13551615
.TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False
Selection.FormatConditions.Add Type:=xlTextString, String:="TRUE", _
TextOperator:=xlContains
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Font
.Color = -16752384
.TintAndShade = 0
End With
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = 13561798
.TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
End Sub
 

greatparthi

New Member
Joined
Feb 14, 2016
Messages
2
Pasting code in expected format. Apologies for my earlier mistake.

Code:
[COLOR=#3F4549][FONT=Helvetica Neue]Sub FormulaInsertion()[/FONT][/COLOR]
[COLOR=#3F4549][FONT=Helvetica Neue]'macro to insert formula[/FONT][/COLOR]
[COLOR=#3F4549][FONT=Helvetica Neue]Range("G1:L101").Formula = "=EXACT(Sheet1!A1, Sheet2!A1)"[/FONT][/COLOR]
[COLOR=#3F4549][FONT=Helvetica Neue]Call FormattingValues[/FONT][/COLOR]
[COLOR=#3F4549][FONT=Helvetica Neue]End Sub[/FONT][/COLOR]
[COLOR=#3F4549][FONT=Helvetica Neue]Sub FormattingValues()[/FONT][/COLOR]
[COLOR=#3F4549][FONT=Helvetica Neue]'[/FONT][/COLOR]
[COLOR=#3F4549][FONT=Helvetica Neue]' Formatting Macro[/FONT][/COLOR]
[COLOR=#3F4549][FONT=Helvetica Neue]'[/FONT][/COLOR]
[COLOR=#3F4549][FONT=Helvetica Neue]Range("G1:L101").Select[/FONT][/COLOR]
[COLOR=#3F4549][FONT=Helvetica Neue]Selection.FormatConditions.Add Type:=xlTextString, String:="FALSE", _[/FONT][/COLOR]
[COLOR=#3F4549][FONT=Helvetica Neue]TextOperator:=xlContains[/FONT][/COLOR]
[COLOR=#3F4549][FONT=Helvetica Neue]Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority[/FONT][/COLOR]
[COLOR=#3F4549][FONT=Helvetica Neue]With Selection.FormatConditions(1).Font[/FONT][/COLOR]
[COLOR=#3F4549][FONT=Helvetica Neue].Color = -16383844[/FONT][/COLOR]
[COLOR=#3F4549][FONT=Helvetica Neue].TintAndShade = 0[/FONT][/COLOR]
[COLOR=#3F4549][FONT=Helvetica Neue]End With[/FONT][/COLOR]
[COLOR=#3F4549][FONT=Helvetica Neue]With Selection.FormatConditions(1).Interior[/FONT][/COLOR]
[COLOR=#3F4549][FONT=Helvetica Neue].PatternColorIndex = xlAutomatic[/FONT][/COLOR]
[COLOR=#3F4549][FONT=Helvetica Neue].Color = 13551615[/FONT][/COLOR]
[COLOR=#3F4549][FONT=Helvetica Neue].TintAndShade = 0[/FONT][/COLOR]
[COLOR=#3F4549][FONT=Helvetica Neue]End With[/FONT][/COLOR]
[COLOR=#3F4549][FONT=Helvetica Neue]Selection.FormatConditions(1).StopIfTrue = False[/FONT][/COLOR]
[COLOR=#3F4549][FONT=Helvetica Neue]Selection.FormatConditions.Add Type:=xlTextString, String:="TRUE", _[/FONT][/COLOR]
[COLOR=#3F4549][FONT=Helvetica Neue]TextOperator:=xlContains[/FONT][/COLOR]
[COLOR=#3F4549][FONT=Helvetica Neue]Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority[/FONT][/COLOR]
[COLOR=#3F4549][FONT=Helvetica Neue]With Selection.FormatConditions(1).Font[/FONT][/COLOR]
[COLOR=#3F4549][FONT=Helvetica Neue].Color = -16752384[/FONT][/COLOR]
[COLOR=#3F4549][FONT=Helvetica Neue].TintAndShade = 0[/FONT][/COLOR]
[COLOR=#3F4549][FONT=Helvetica Neue]End With[/FONT][/COLOR]
[COLOR=#3F4549][FONT=Helvetica Neue]With Selection.FormatConditions(1).Interior[/FONT][/COLOR]
[COLOR=#3F4549][FONT=Helvetica Neue].PatternColorIndex = xlAutomatic[/FONT][/COLOR]
[COLOR=#3F4549][FONT=Helvetica Neue].Color = 13561798[/FONT][/COLOR]
[COLOR=#3F4549][FONT=Helvetica Neue].TintAndShade = 0[/FONT][/COLOR]
[COLOR=#3F4549][FONT=Helvetica Neue]End With[/FONT][/COLOR]
[COLOR=#3F4549][FONT=Helvetica Neue]Selection.FormatConditions(1).StopIfTrue = False[/FONT][/COLOR]
[COLOR=#3F4549][FONT=Helvetica Neue]Selection.Borders(xlDiagonalDown).LineStyle = xlNone[/FONT][/COLOR]
[COLOR=#3F4549][FONT=Helvetica Neue]Selection.Borders(xlDiagonalUp).LineStyle = xlNone[/FONT][/COLOR]
[COLOR=#3F4549][FONT=Helvetica Neue]With Selection.Borders[/FONT][/COLOR]
[COLOR=#3F4549][FONT=Helvetica Neue].LineStyle = xlContinuous[/FONT][/COLOR]
[COLOR=#3F4549][FONT=Helvetica Neue].ColorIndex = 0[/FONT][/COLOR]
[COLOR=#3F4549][FONT=Helvetica Neue].TintAndShade = 0[/FONT][/COLOR]
[COLOR=#3F4549][FONT=Helvetica Neue].Weight = xlThin[/FONT][/COLOR]
[COLOR=#3F4549][FONT=Helvetica Neue]End With[/FONT][/COLOR]
[COLOR=#3F4549][FONT=Helvetica Neue]End Sub[/FONT][/COLOR]
 

Forum statistics

Threads
1,082,047
Messages
5,362,881
Members
400,696
Latest member
Kclynn

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top