PDA

View Full Version : refedit range comparison



impius
02-23-2009, 04:53 PM
Hello...

I have created a userform with 3 refedit controls on it. This userform will be part of a charting add-in. I need to ensure that the user selects the same range for all three refedits...i.e refedit1=a5:a22, refedit2=b5:b22, refedit3=c5:c22. So the column can be different, the row selection needs to be the same...Any ideas??

Thanks!

mdmackillop
02-23-2009, 05:04 PM
You only need one RefEdit, create offsets from it for the other ranges

Private Sub CommandButton1_Click()
Dim Rng1 As Range, Rng2 As Range, Rng3 As Range
Set Rng1 = Range(RefEdit1)
Set Rng2 = Rng1.Offset(, 1)
Set Rng3 = Rng1.Offset(, 2)
Rng1.Interior.ColorIndex = 6
Rng2.Interior.ColorIndex = 7
Rng3.Interior.ColorIndex = 8

End Sub

impius
02-23-2009, 05:11 PM
Thanks...But I have refedit1, 2 and 3 on a userform, each refedit and thus column could be unspecified distance from refedit1. So, your solution would not work would it?

mdmackillop
02-23-2009, 05:40 PM
Correct. I misunderstood your requirements

Jan Karel Pieterse
02-23-2009, 11:15 PM
Like this:
Public Function AreRowsSame(oRng1 As Range, oRng2 As Range, oRng3 As Range) As Boolean
If oRng1.EntireRow.Address = oRng2.EntireRow.Address _
And oRng1.EntireRow.Address = oRng3.EntireRow.Address _
And oRng2.EntireRow.Address = oRng3.EntireRow.Address Then
AreRowsSame = True
End If
End Function
Sub Test()
MsgBox AreRowsSame(Range("A1:A10"), Range("d1:d10"), Range("ee2:ee10"))
End Sub

impius
02-24-2009, 10:45 AM
Thanks...
So for my purposes would I change oRng1, 2 and 3 to my refedit controls?

Jan Karel Pieterse
02-24-2009, 10:54 AM
Yes.

impius
02-24-2009, 11:27 AM
Okay...I have incorporated the function into my code, but I need a little further assistance...

Private Sub CommandButton1_Click()
Dim x, y, yy, yyy
Dim namex, namexx, namexxx As String
Dim datapoints
x = RefEdit1
y = RefEdit2
yy = RefEdit3
yyy = RefEdit5
datapoints = TextBox3
namex = xaxisname
namexx = TextBox4
namexxx = TextBox5
MsgBox AreRowsSame(Range("A1:A10"), Range("d1:d10"), Range("ee2:ee10"))



How do I input refedit1, 2 and 3 (or x, y, yy) into the arerowssame function?

I tried AreRowsSame(x,... But it gave me an error.

Thanks again!