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
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
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]
 
Upvote 0

Forum statistics

Threads
1,214,606
Messages
6,120,479
Members
448,967
Latest member
visheshkotha

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top