Daar is ie weer...........
ik gebruik onderstaande routine om cellen om te wisselen.
nu blijkt dat ik het toch anders moet doen.
ik wil graag een aantal cellen gelijk omruilen.
Bv cellen ("A1:G1") ruilen met ("A6:G6")
deze formule gebruik ik:
Private Sub omwisselen(control As IRibbonControl)
Dim a As Variant
Dim aL As Variant
Dim msg As String
If Selection.Cells.Count = 2 Then
If Selection.Areas.Count = 1 Then
If (Selection.Cells(1).Formula = CStr(Selection.Cells(1)) Or _
IsNumeric(Selection.Cells(1).Formula)) And (Selection.Cells(2).Formula = _
CStr(Selection.Cells(2)) Or IsNumeric(Selection.Cells(2).Formula)) Then
a = Selection.Cells(1).Value
aL = Selection.Cells(1).NumberFormat
Selection.Cells(1) = Selection.Cells(2).Value
Selection.Cells(1).NumberFormat = Selection.Cells(2).NumberFormat
Selection.Cells(2) = a
Selection.Cells(2).NumberFormat = aL
Else
msg = "De selectie bevat formules. Er wordt niet gewisseld."
End If
Else
If (Selection.Areas(1).Formula = CStr(Selection.Areas(1)) Or _
IsNumeric(Selection.Areas(1).Formula)) And (Selection.Areas(2).Formula = _
CStr(Selection.Areas(2)) Or IsNumeric(Selection.Areas(2).Formula)) Then
a = Selection.Areas(1).Value
aL = Selection.Areas(1).NumberFormat
Selection.Areas(1) = Selection.Areas(2).Value
Selection.Areas(1).NumberFormat = Selection.Areas(2).NumberFormat
Selection.Areas(2) = a
Selection.Areas(2).NumberFormat = aL
Else
msg = "De selectie bevat formules. Er wordt niet gewisseld."
End If
End If
Else
msg = "Het aantal geselecteerde cellen en/of gebieden is ongelijk aan twee."
End If
If Len(msg) > 0 Then
MsgBox msg, vbInformation, "Namen zijn omgewisseld"
End If
End Sub
Dank voor reactie,
fijne avond
Ronald
ik gebruik onderstaande routine om cellen om te wisselen.
nu blijkt dat ik het toch anders moet doen.
ik wil graag een aantal cellen gelijk omruilen.
Bv cellen ("A1:G1") ruilen met ("A6:G6")
deze formule gebruik ik:
Private Sub omwisselen(control As IRibbonControl)
Dim a As Variant
Dim aL As Variant
Dim msg As String
If Selection.Cells.Count = 2 Then
If Selection.Areas.Count = 1 Then
If (Selection.Cells(1).Formula = CStr(Selection.Cells(1)) Or _
IsNumeric(Selection.Cells(1).Formula)) And (Selection.Cells(2).Formula = _
CStr(Selection.Cells(2)) Or IsNumeric(Selection.Cells(2).Formula)) Then
a = Selection.Cells(1).Value
aL = Selection.Cells(1).NumberFormat
Selection.Cells(1) = Selection.Cells(2).Value
Selection.Cells(1).NumberFormat = Selection.Cells(2).NumberFormat
Selection.Cells(2) = a
Selection.Cells(2).NumberFormat = aL
Else
msg = "De selectie bevat formules. Er wordt niet gewisseld."
End If
Else
If (Selection.Areas(1).Formula = CStr(Selection.Areas(1)) Or _
IsNumeric(Selection.Areas(1).Formula)) And (Selection.Areas(2).Formula = _
CStr(Selection.Areas(2)) Or IsNumeric(Selection.Areas(2).Formula)) Then
a = Selection.Areas(1).Value
aL = Selection.Areas(1).NumberFormat
Selection.Areas(1) = Selection.Areas(2).Value
Selection.Areas(1).NumberFormat = Selection.Areas(2).NumberFormat
Selection.Areas(2) = a
Selection.Areas(2).NumberFormat = aL
Else
msg = "De selectie bevat formules. Er wordt niet gewisseld."
End If
End If
Else
msg = "Het aantal geselecteerde cellen en/of gebieden is ongelijk aan twee."
End If
If Len(msg) > 0 Then
MsgBox msg, vbInformation, "Namen zijn omgewisseld"
End If
End Sub
Dank voor reactie,
fijne avond
Ronald