Generate Weekending date

Bryan123

New Member
Joined
May 23, 2019
Messages
41
Hi All,

I am doing Visual Basic and would like to know how i can convert this statement to return the weekending date. The result will only give me a count of days from sunday to the date on transdate.value but not the weekending.
WE.Value = Weekday(transdate.Value, vbSunday)

Please help me out!
Bryan
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Try this:
Code:
WE.Value = transdate.Value + (7 - Weekday(transdate.Value))
 
Upvote 0
Does it make any difference if you remove the ".Value" references, i.e.
Code:
WE = transdate + (7 - Weekday(transdate))
If not, please answer the following questions:
How are WE and transdate declared?
What data type are they?
What is the value of transdate when the code runs?

Here is a simple example showing it working:
Code:
Sub Test()

    Dim transdate As Date
    Dim WE As Date
    
    transdate = Date
    WE = transdate + (7 - Weekday(transdate))
    
    MsgBox WE
    
End Sub
 
Last edited:
Upvote 0
Hi, still having the same error.

1.
If ComboBox6.Value = "PEGA sampling" Then
lRow = ws.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
With ws
.Cells(lRow, 19).Value = transdate.Value
2. This is just a date transferred from excel sheet to a textbox
3. i also have this when transferring data from excel sheet to the textboxes:
With Me.ComboBox1
.Clear
Application.ScreenUpdating = False
ListItems = employee
ListItems1 = employee2
For i = 1 To UBound(ListItems, 1)
.AddItem ListItems(i, 1)
.AddItem ListItems1(i, 1)
Next i
ComboBox1.ListIndex = 0
End With
 
Upvote 0
I am not sure what you are trying to show me with the code in youre previous post, and what that has to do with your original question.

Please post your original code, with my inserted function, and tell me which line of code is highlighted when the error occurs and you click "Debug".
 
Upvote 0
I'm so sorry for the confusion. I think I'll have to use your function instead since it still has the same idea. Thank you very much for the help.
 
Upvote 0

Forum statistics

Threads
1,224,818
Messages
6,181,152
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top