Re: All Possible Combinations from Single Column
You're welcome
Re: All Possible Combinations from Single Column
You're welcome
Re: Copying parts of data into master data sheet
I'm not quite sure what you would want to do !!
Please show an example.
Re: All Possible Combinations from Single Column
Try this for results in "B".
Sub Combinations()
'Ref PCG
Dim rRng As Range, p
Dim vElements, lRow As Long, vresult As Variant
Set rRng = Range("A1", Range("A1").End(xlDown))
p = 3
vElements = Application.Index(Application.Transpose(rRng), 1, 0)
ReDim vresult(1 To p)
Call CombinationsNP(vElements, CInt(p), vresult, lRow, 1, 1)
End Sub
Sub CombinationsNP(vElements As Variant, p As Integer, vresult As Variant, lRow As Long, iElement As Integer, iIndex As Integer)
Dim i As Integer
For i = iElement To UBound(vElements)
vresult(iIndex) = vElements(i)
If iIndex = p Then
lRow = lRow + 1
Range("B" & lRow) = Join(vresult, ", ")
'Range("C" & lRow).Resize(, p) = vresult'Multi column Result
Else
Call CombinationsNP(vElements, p, vresult, lRow, i + 1, iIndex + 1)
End If
Next i
End Sub
Display More
Re: Copying parts of data into master data sheet
Try this for results on sheet master.
NB:- Run the code on each weeks new data, in data sheet (columns A & B), replacing the previous weeks data by the new data before running code.
Sub Mstr()
Dim Rng As Range, Dn As Range, n As Long
Dim Dic As Object, col As Long, mRng As Range
Set Rng = Range(Range("A1"), Range("A" & Rows.Count).End(xlUp))
With Sheets("Master").Range("A2")
.Value = "1"
.AutoFill Destination:=.Resize(Rng(Rng.Count)), Type:=xlFillSeries
With .Parent
Set mRng = .Range(.Range("A2"), .Range("A" & Rows.Count).End(xlUp))
col = .Range("A1").CurrentRegion.Columns.Count
.Cells(1, col + 1).Value = "Week " & col
End With
End With
Set Dic = CreateObject("scripting.dictionary")
Dic.CompareMode = vbTextCompare
For Each Dn In Rng: Dic(Dn.Value) = Dn.Offset(, 1).Value: Next
For Each Dn In mRng
If Dic.exists(Dn.Value) Then
Dn.Offset(, col) = Dic(Dn.Value)
End If
Next Dn
End Sub
Display More
Re: Symbol Drop Down List
You're welcome
Re: Symbol Drop Down List
Run the first code to fill your range with validation list of the Words "Tick, Cross & "N/A"
Right click the sheet tab select "View Code" vbWindow appears, Paste the second code in that window,
Close VbWindow
When you now select any of the validation cells and select either "Tick , "Cross or "N/A" the appropriate symbol should appear.
'Code1
Private Sub CommandButton1_Click()
Dim Rng As Range, Dn As Range
Set Rng = Range("K2:K75")
For Each Dn In Rng
With Dn.Validation
.Delete
.Add Type:=xlValidateList, Formula1:="Tick,Cross,N/A"
End With
Next Dn
End Sub
'Code2
Private Sub Worksheet_Change(ByVal Target As Range)
Dim Rng As Range, Dn As Range
Set Rng = Range("K2:K75")
Application.EnableEvents = False
If Target.Count = 1 Then
If Not Intersect(Target, Rng) Is Nothing Then
Select Case Target
Case "Tick": Target.Value = ChrW(10004): Target.Font.Name = "Calibra(Body)"
Case "Cross": Target = ChrW(10008): Target.Font.Name = "Calibra(Body)"
Case "N/A": Target.Font.Name = "Calibra(body)"
End Select
End If
End If
Application.EnableEvents = True
End Sub
Display More
Re: Disable duplicate entrance of data into the worksheet
I'm not sure why your unable to get the code to work, perhaps you are not loading it properly !!!
Here is an example file.
This code has been modified to enable you to copy/paste Single and multiple cells and still get them to clear if duplicate.
It also has instructions to save code.
https://app.box.com/s/wi2hmczw59b7qbdfo5ss8lv8wqxx2ga1
Re: Disable duplicate entrance of data into the worksheet
Try this:-
NB:- This code should not allow any duplicate in columns "A & G"
Private Sub Worksheet_Change(ByVal Target As Range)
Dim RngA As Range, Dn As Range, Col As Long
Dim RngG As Range, Rng As Range
Application.EnableEvents = False
If Target.Column = 1 Or Target.Column = 7 Then
Set RngA = Range(Range("A1"), Range("A" & Rows.Count).End(xlUp))
Set RngG = Range(Range("G1"), Range("G" & Rows.Count).End(xlUp))
Set Rng = Union(RngA, RngG)
For Each Dn In Rng
If UCase(Dn.Value) = UCase(Target.Value) And Not Dn.Address = Target.Address Then
MsgBox "Invalid Entry"
Target.Value = ""
End If
Next
End If
Application.EnableEvents = True
End Sub
Display More
Re: Disable duplicate entrance of data into the worksheet
Try this for columns "A & G":-
Private Sub Worksheet_Change(ByVal Target As Range)
Dim Rng As Range, Dn As Range, Col As Long
Application.EnableEvents = False
If Target.Column = 1 Or Target.Column = 7 Then
Col = IIf(Target.Column = 1, 7, 1)
Set Rng = Range(Cells(1, Col), Cells(Rows.Count, Col).End(xlUp))
For Each Dn In Rng
If Dn.Value = Target.Value Then
MsgBox "Invalid Entry"
Target.Value = ""
End If
Next
End If
Application.EnableEvents = True
End Sub
Display More
Re: Import selected option button value in a group back to user form
This may be wide of the mark, but I thought you could, instead of passing the target.row to the userform code, you could pass the actual "Target" as a range. Being a range object you could then find all the row values using the Target .offset(,??) value.
Then you could loop the option buttons "Labels" until you found the correct reply, and then set it to "true"
Re: Excel VBA - Search and Remove String Data
You're welcome
Re: Excel VBA - Search and Remove String Data
Try:-
Sub Rep()
Dim Ray As Variant, Ray2 As Variant, n As Long
Ray = Sheets("Sheet1").Range("A1").CurrentRegion.Resize(, 1)
Ray2 = Sheets("Sheet2").Range("A2").CurrentRegion.Resize(, 1)
With CreateObject("scripting.dictionary")
.CompareMode = vbTextCompare
For n = 1 To UBound(Ray2, 1)
.Item(Ray2(n, 1)) = Empty
Next
For n = 2 To UBound(Ray, 1)
If .exists(Trim(Split(Ray(n, 1), "-")(1))) Then
Ray(n, 1) = Trim(Split(Ray(n, 1), "-")(0))
End If
Next n
End With
Sheets("Sheet1").Range("A1").Resize(UBound(Ray, 1)) = Ray
End Sub
Display More
Re: Count Cell with specific color
Try this:-
Sub cCols()
Dim Rng As Range, Dn As Range, R As Long, G As Long, Y As Long
Set Rng = Range(Range("N39"), Range("N" & Rows.Count).End(xlUp))
For Each Dn In Rng
If Not temp = Dn.MergeArea.Address Then
Select Case Dn.DisplayFormat.Interior.Color
Case 255: R = R + 1
Case 5296274: G = G + 1
Case 65535: Y = Y + 1
End Select
End If
temp = Dn.MergeArea.Address
Next Dn
With Sheets("Dash Board")
.Range("D7").Value = R
.Range("D8").Value = Y
.Range("D9").Value = G
End With
End Sub
Display More
Re: Duplicate rows macro and apply text to each duplicate set based on a list
You're welcome
Re: Duplicate rows macro and apply text to each duplicate set based on a list
Try this:-
Sub Data()
Dim Rng As Range, Dn As Range, Data As Range
Set Data = Sheets("Data").Range("A1").CurrentRegion
Set Data = Data.Offset(1, 1).Resize(Data.Rows.Count - 1, Data.Columns.Count - 1)
With Sheets("LOCATIONS")
Set Rng = .Range(.Range("A1"), .Range("A" & Rows.Count).End(xlUp))
End With
With Sheets("RESULT")
c = 2
For Each Dn In Rng
Range("A" & c).Resize(Data.Rows.Count) = Dn
Range("B" & c).Resize(Data.Rows.Count, Data.Columns.Count).Value = Data.Value
c = c + Data.Rows.Count
Next Dn
End With
End Sub
Display More
Re: How to get 2 lines in Message Box in VBA
You're welcome
Re: Summing multidimensional arrays
Perhaps:-
Results column "A"
Dim ray, R As Long, Ac As Long, c As Long
ray = [{1,2,3;2,3,4;3,4,5;4,5,6}] ' and this would return {6;9;12;15}.
ReDim nRay(1 To UBound(ray, 1))
For R = 1 To UBound(ray, 1)
c = c + 1
For Ac = 1 To UBound(ray, 2)
nRay(c) = nRay(c) + ray(R, Ac)
Next Ac
Next R
Range("A1").Resize(UBound(ray, 1)).Value = Application.Transpose(nRay)
Re: Highlight date clashes in Annual leave between staff
This is another workaround, hopefully you will not notice any problems.
Private Sub Worksheet_Change(ByVal Target As Range)
'Another workaround Placing dummy ("$A$1")value in array, to Make minimum of 2 values, on entry of first date.
'This should enable the first and subsequent dates to be processed. !!!
Dim Dn As Range, nR As Range, c As Long, p As Long
Dim ray As Variant, Rng As Range, Q As Variant
Dim Dic As Object, nDic As Object
Dim n As Long 'Date######
Dim R As Range, Dt As Date
Dim nCol As Integer
Dim rCols As Variant, col As Variant, K As Variant
If Not Intersect(Target, Range("A:B,K:L,U:S")) Is Nothing Then
rCols = Array("A", "K", "U")
Set Dic = CreateObject("Scripting.Dictionary")
Dic.CompareMode = 1
Set nDic = CreateObject("Scripting.Dictionary")
nDic.CompareMode = 1
nCol = 2
For Each col In rCols
Set Rng = Range(Range(col & "1"), Range(col & Rows.Count).End(xlUp))
Rng.Interior.ColorIndex = xlNone
For Each Dn In Rng.Areas
For Each R In Dn
If IsDate(R) Then
Set nR = IIf(R.Offset(, 1) = "", R, R.Offset(, 1))
For Dt = R To nR
If Not Dic.Exists(Dt) Then
Dic.Add Dt, R
Else
Set Dic(Dt) = Union(Dic(Dt), R)
End If
Next Dt
End If
Next R
Next Dn
Next col
For Each K In Dic.keys
' MsgBox nDic(Dic(K).Address)
If Dic.Item(K).Count > 1 Then
nDic(Dic(K).Address) = Empty
Else
nDic("$A$1") = Empty
End If
Next K
If nDic.Count > 1 Then
ray = Application.Transpose(nDic.keys)
ReDim nray(1 To UBound(ray, 1) + 1, 1 To 2) As Range
c = 0
For n = 1 To UBound(ray, 1)
If Not ray(n, 1) = "" Then
c = c + 1
For p = n To UBound(ray, 1)
If Not ray(p, 1) = "" Then
If nray(c, 1) Is Nothing Then
Set nray(c, 1) = Range(ray(p, 1))
ray(n, 1) = ""
ElseIf Not Intersect(nray(c, 1), Range(ray(p, 1))) Is Nothing Then
Set nray(c, 1) = Union(nray(c, 1), Range(ray(p, 1)))
ray(p, 1) = ""
End If
End If
Next p
End If
Next n
For n = 1 To c
nCol = nCol + 1
nCol = IIf(nCol = 13, 3, nCol)
If Not nray(n, 1).Address = "$A$1" Then nray(n, 1).Interior.ColorIndex = nCol
Next n
End If
End If
End Sub
Display More