Consulting

Results 1 to 2 of 2

Thread: Text in textbox only updates once

  1. #1
    VBAX Newbie
    Joined
    Apr 2020
    Posts
    1
    Location

    Text in textbox only updates once

    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?
    Last edited by Bob Phillips; 04-30-2020 at 01:29 AM. Reason: Added code tags

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Is it just using E6 rather than the cell E6

    DayTextBox.Text = WeekdayName(Weekday(Range("E6").Value, vbMonday), False, vbMonday)
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •