I am creating a calendar feature which takes inputs from a form and based off that I will assign into a dynamic calendar.
The problem is that my third textbox and subsequent textbox will not be directly below the previous textbox created.
.
It is created in the position of the second textbox. How can I calculate the bottom position of the last created textbox?
Also how can I code it to automatically increase the row height accordingly when there is more than one textbox.
If Not searchCell Is Nothing Then
Dim targetCell As Range
Dim targetColumn As Long
targetRow = searchCell.row
targetColumn = searchCell.Column
For Each targetCell In searchRange
If IsDate(targetCell.Value) Then
Dim currentDate As Date
currentDate = DateValue(targetCell.Value)
' Compare currentDate with SVDateValue (day and month)
If Day(currentDate) = Day(searchDate) And Month(currentDate) = Month(searchDate) Then
'MsgBox currentDate
'MsgBox Day(searchDate)
'MsgBox Month(currentDate)
'MsgBox Month(searchDate)
' Find the original textbox, if any
Dim originalTextbox As Shape
For Each originalTextbox In calendarSheet.Shapes
If originalTextbox.Type = msoTextBox Then ' Check if the shape is a textbox
If originalTextbox.TopLeftCell.row = targetRow And originalTextbox.TopLeftCell.Column = targetColumn Then
Exit For
End If
End If
Next originalTextbox
' Calculate the top position for the new textbox (below the original)
Dim topPosition As Double
If Not originalTextbox Is Nothing Then
topPosition = originalTextbox.Top + originalTextbox.Height + 1 ' Add some spacing
Else
topPosition = calendarSheet.Cells(targetRow, targetColumn).Top
End If
Dim tb As Shape
Set tb = calendarSheet.Shapes.AddTextbox(Orientation:=msoTextOrientationHorizontal, _
Left:=calendarSheet.Cells(targetCell.row, targetCell.Column).Left, _
Top:=topPosition, _
Width:=calendarSheet.Cells(targetCell.row, targetCell.Column).Width, _
Height:=80)
'Height:=calendarSheet.Cells(targetCell.row, targetCell.Column).Height) Automatic Fit to Box
' Set properties for the TextBox
tb.Fill.Transparency = 1 ' Fully transparent fill
tb.Line.Visible = msoFalse ' No border
' Set TextBox text to SVDate and company values
tb.TextFrame2.TextRange.Text = SVDateValue & vbCrLf & DPValue & vbCrLf & companyValue & vbCrLf & SVTimeValue
' Change color of SVDateValue text to white
'tb.TextFrame2.textRange.Characters(1, Len(SVDateValue)).Font.Fill.ForeColor.RGB = RGB(255, 255, 255)
tb.TextFrame2.TextRange.Characters(1, Len(SVDateValue)).Font.Fill.Visible = msoFalse 'Making ServiceDate Color to Not Filled
End If
End If
Next targetCell
' Update the month and year cells
'calendarSheet.Range("D1").Value = extractedMonth
'calendarSheet.Range("G1").Value = extractedYear
Else
MsgBox "Date not found in the specified range.", vbExclamation
End If