PDA

View Full Version : Text in textbox only updates once



lewisj
04-29-2020, 07:45 PM
Hi, I am quite a beginner in VBA, just playing around with a few things.
I have a spreadsheet with a date, and I've made a button to add 7 days to the date, which works fine. Then I've made a text box to display the weekday to check if it's correct. I made this into a text box so I can set it to not print.
This is the code I've made:


Private Sub AddWeek_Click()
Dim newDate As Date, oldDate As Date
oldDate = Cells(6, "E").Value
newDate = DateAdd("d", 7, oldDate)
Range("E6").Value = newDate
DayTextBox.Text = WeekdayName(Weekday(E6, vbMonday), False, vbMonday)
End Sub

The problem is, when I click the button it does say the correct date in the text box. But only once. If I change the date in cell E6 and click the button again, it still says the same day. Do I need to make it clear the text box before entering the new information or something like that?

Bob Phillips
04-30-2020, 01:41 AM
Is it just using E6 rather than the cell E6


DayTextBox.Text = WeekdayName(Weekday(Range("E6").Value, vbMonday), False, vbMonday)