testing for range of values

cocopops2001

Board Regular
Joined
Apr 18, 2011
Messages
112
when testing for range of values what is the best way to do it, i want to copy a sheet over to a new book. I want to test five variables and if all five do not match then paste a certain sheet into the new book. can i use something like this.

Code:
 If Sheet1.Range("a1", "D5", "n50", "M10", "C6").Value <> Thisworkbook.Sheet(1).Range("a1", "D5", "n50", "M10", "C6").Value Then

''''''copy the sheets

End If

or am i better defining my range as a variable and then testing against that?
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
I don't know if it's the best way but I would be inclined to concatenate the 5 values from both places and do a single comparison on the concatenated values.

Gary
 
Upvote 0
im quite new to programming and i dont understand what that means. can you give me an example line of code please?
 
Upvote 0
Concatenate strings (adds) all the values together. You would only have to do 1 test instead of 5.

You could use the "Concatenate" formula / function on the worksheets to do it for you.

In an unused or hidden cell on both sheets:

=CONCATENATE(A1,D5,N50,M10,C6)

Then you would check to see if both those cells are the same.

Or, basically the same thing in code

Activesheet.Range("A1").value & Activesheet.Range("D5").value & ...

Notice the & operator. Plus (+) can also work but if the values happen to be numeric it will sum the values instead of just stringing all the characters together.

Gary
 
Upvote 0

Forum statistics

Threads
1,224,557
Messages
6,179,508
Members
452,918
Latest member
Davion615

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