PDA

View Full Version : sum of 3 dates



asdzxc
10-10-2013, 05:11 AM
=Sum(Weekday(A2), Weekday(A3), Weekday(A4))
the above formular is OK in Excel sheet but putting it in macro, there is Compile error :
Sub or function not defined.

H2 = Sum(Weekday(A2), Weekday(A3), Weekday(A4))
If H2 < 15 Then

Aussiebear
10-10-2013, 05:21 AM
Please show us the macro you are currently trying to use. Simply implying two lines of the macro isn't very useful.

asdzxc
10-10-2013, 05:24 AM
Workbooks.OpenText Filename:="F:\Users\H\Documents\a.txt", Origin:=936, _
StartRow:=1, DataType:=xlDelimited, TextQualifier:=xlDoubleQuote, _
ConsecutiveDelimiter:=False, Tab:=True, Semicolon:=False, Comma:=False _
, Space:=False, Other:=False, FieldInfo:=Array(1, 1), _
TrailingMinusNumbers:=True '
LR = Range("A" & Rows.Count).End(xlUp).Row
Range("A1:A" & LR).TextToColumns Destination:=Range("A1"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=True, Tab:=False, _
Semicolon:=False, Comma:=True, Space:=True, Other:=False, FieldInfo:=Array(1, 1), _
TrailingMinusNumbers:=True
Range("B2:C" & LR).Delete Shift:=xlToLeft
Columns("A:A").ColumnWidth = 14
LR = Cells(Rows.Count, "A").End(xlUp).Row
If Range("A2").End(xlDown).Row > 500 Then
Range("A2:A" & LR - 500).EntireRow.Delete
End If
Columns("E:E").Select
Selection.Copy
Range("B1").Select
ActiveSheet.Paste
Columns("C:C").Select
Application.CutCopyMode = False
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
H2 = Sum(Weekday(A2), Weekday(A3), Weekday(A4))
If H2 < 15 Then
Columns("A:B").Select
Selection.Copy
Range("D1").Select
ActiveSheet.Paste
Range("G1").Select
ActiveSheet.Paste
Columns("A:A").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
With Range("b2", Range("b" & Rows.Count).End(xlUp)).Offset(, -1)
.Formula = "=if(b3="""","""",if(month(b2)=month(b3),1,""""))"
.Value = .Value
On Error Resume Next
.SpecialCells(2, 1).Offset(0, 1).Delete Shift:=xlUp
.SpecialCells(2, 1).Offset(0, 2).Delete Shift:=xlUp
On Error GoTo 0
End With
Columns(1).Delete
Columns("A:C").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Columns("G:H").Select
Selection.Cut
Range("A1").Select
ActiveSheet.Paste
Columns(1).Insert
With Range("b2", Range("b" & Rows.Count).End(xlUp)).Offset(, -1)
.Formula = "=if(and(weekday(b2,2)<weekday(b3,2),b3<>""""),1,"""")"
.Value = .Value
On Error Resume Next
.SpecialCells(2, 1).Offset(0, 1).Delete Shift:=xlUp
.SpecialCells(2, 1).Offset(0, 2).Delete Shift:=xlUp
On Error GoTo 0
End With
Columns(1).Delete
Range("A1").Select
ActiveCell.FormulaR1C1 = "week"
Range("D1").Select
ActiveCell.FormulaR1C1 = "month"
End Sub

asdzxc
10-10-2013, 09:04 PM
Solved