Hello all
I have reached a desperate point which I would really appreciate help on.
The code below was orginally used on an unfiltered list with the data populating it spread on separate worksheets. It worked without any problems.
I have now centralised the data on one sheet for easier management and filter for what I need. The problem I have is that I cant make it populate the form from the filtered list and certainly cant write back to the vacant cells relevant to it.
There is another issue!!! The code now needs to identify if there is a vacant cell next to the entry and then if so write as normal if not insert a new column to accomodate the data. The new columns would be in a named range of columns e.g. "Register".
Therefore it needs a check to make sure that there is space and because its a filtered list make sure that any other filtered option follows the same process i.e only inserts a new column if no blank available. That means if one instance of the filter needed a new column the others would not until they filled the blanks created by it.
Anyway heres the code
Public Sub CommandButton1_Click()'appears on form
Let i = 0
Let r = 5
'inserts column for updated data including current date
' The date would be replaced by a comment added to each cell written to showing the current date
Columns("D
").Select
Selection.Insert Shift:=xlToRight
Range("D3").Select
ActiveCell.FormulaR1C1 = "=TODAY()"
copieddate = Cells(3, 4).Value ' copies the date so that the fomula doesnt cause problems
Cells(3, 4) = copieddate
Range("D3
33").Select
'obviously for appearance purposes only the follwing formats the column
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlThick
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
'loop to insert marks as present or absent dependent on checkbox value and whether its there or not
For i = 1 To 30
If Me.Controls("CheckBox" & i).Value = True Then Cells(r, 4) = "/" Else Cells(r, 4) = "A"
If Me.Controls("CheckBox" & i).Visible = False Then Cells(r, 4) = ""
r = r + 1
Next i
UserForm1.Hide
End Sub
Public Sub UserForm_Initialize()
Let i = 0 'index for checkbox
Let r = 5 ' index for row number
'loop to define checkbox caption values if false then no checkbox
For i = 1 To 30
If Cells(r, 1) = "" Then Me.Controls("CheckBox" & i).Visible = False Else Me.Controls("CheckBox" & i).Caption = Cells(r, 1) & " " & Cells(r, 2)
r = r + 1
Next i
End Sub
This may be alot to ask but it has reached the final piece in a big jigsaw so to speak.
Many thanks in advance.
Neil
I have reached a desperate point which I would really appreciate help on.
The code below was orginally used on an unfiltered list with the data populating it spread on separate worksheets. It worked without any problems.
I have now centralised the data on one sheet for easier management and filter for what I need. The problem I have is that I cant make it populate the form from the filtered list and certainly cant write back to the vacant cells relevant to it.
There is another issue!!! The code now needs to identify if there is a vacant cell next to the entry and then if so write as normal if not insert a new column to accomodate the data. The new columns would be in a named range of columns e.g. "Register".
Therefore it needs a check to make sure that there is space and because its a filtered list make sure that any other filtered option follows the same process i.e only inserts a new column if no blank available. That means if one instance of the filter needed a new column the others would not until they filled the blanks created by it.
Anyway heres the code
Public Sub CommandButton1_Click()'appears on form
Let i = 0
Let r = 5
'inserts column for updated data including current date
' The date would be replaced by a comment added to each cell written to showing the current date
Columns("D
Selection.Insert Shift:=xlToRight
Range("D3").Select
ActiveCell.FormulaR1C1 = "=TODAY()"
copieddate = Cells(3, 4).Value ' copies the date so that the fomula doesnt cause problems
Cells(3, 4) = copieddate
Range("D3
'obviously for appearance purposes only the follwing formats the column
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlThick
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
'loop to insert marks as present or absent dependent on checkbox value and whether its there or not
For i = 1 To 30
If Me.Controls("CheckBox" & i).Value = True Then Cells(r, 4) = "/" Else Cells(r, 4) = "A"
If Me.Controls("CheckBox" & i).Visible = False Then Cells(r, 4) = ""
r = r + 1
Next i
UserForm1.Hide
End Sub
Public Sub UserForm_Initialize()
Let i = 0 'index for checkbox
Let r = 5 ' index for row number
'loop to define checkbox caption values if false then no checkbox
For i = 1 To 30
If Cells(r, 1) = "" Then Me.Controls("CheckBox" & i).Visible = False Else Me.Controls("CheckBox" & i).Caption = Cells(r, 1) & " " & Cells(r, 2)
r = r + 1
Next i
End Sub
This may be alot to ask but it has reached the final piece in a big jigsaw so to speak.
Many thanks in advance.
Neil