dpaton05
Well-known Member
- Joined
- Aug 14, 2018
- Messages
- 2,352
- Office Version
- 365
- 2016
- Platform
- Windows
I have tried to write some code
This code filters data where column 1 matches LCDt and column 3 matches LCReq and should only return 1 match. I want the service stored in column E of the filtered row to be put into the service column B30 of this range and LCDt is to be put in column A. This will generate a price in H30 of sheet2 and I need it copied back to column H of the filtered row above.
Can someone please help me with this code?
VBA Code:
Sub LateCancel()
Dim ws As Worksheet, sh As Worksheet, sht As Worksheet, QT As String, wb2 As Workbook, WbPath As String, QTPath As String
Dim Serv As String, Month As String, Service As String, LCPrice As String
Set wb2 = ThisWorkbook
QT = "CSS_quoting_tool_29.5.xlsm"
Set sh = wb2.Worksheets("Totals")
'Set sht = Sheets("Cancellations")
Dim LCReq As String: LCReq = sh.Cells(32, 2).Value
Dim LCDt As String: LCDt = sh.Cells(34, 2).Value
WbPath = ThisWorkbook.Path
'CurDir ".."
'CurDir ".."
'QTPath = Left(WbPath, InStrRev(WbPath, "\") - 2)
QTPath = ThisWorkbook.Path & "\..\" & "\..\"
Application.ScreenUpdating = False
'If Not isFileOpen(DocYearName & ".xlsm") Then Workbooks.Open ThisWorkbook.Path & "\" & "Work Allocation Sheets" & "\" & Site & "\" & DocYearName & ".xlsm"
'If Not isFileOpen(QT) Then Workbooks.Open QTPath & "\" & QT
For Each ws In wb2.Worksheets
If ws.Name <> "Cancellations" And ws.Name <> "Totals" And ws.Name <> "Sheet2" Then
With ws.[A3].CurrentRegion
'Autofilter the late cancel date enter in B34 with dates in column 1
.AutoFilter 1, LCDt
'Autofilter the late cancel request number with request numbers in column 3
.AutoFilter 3, LCReq
'Add the service to a varaible
.Offset(1, 5).Value = Service
'With Application.Intersect(.SpecialCells(xlCellTypeVisible), .Offset(1, 0))
' Serv = .Areas(1).Cells(1, 6).Address
'End With
Data.Cells(30, 1) = LCDt
Data.Cells(30, 2) = Service
.Offset(1, 8).Value = LCPrice
.AutoFilter
End With
End If
Next ws
'sh.Range("B32,B34").ClearContents
Application.ScreenUpdating = True
End Sub
This code filters data where column 1 matches LCDt and column 3 matches LCReq and should only return 1 match. I want the service stored in column E of the filtered row to be put into the service column B30 of this range and LCDt is to be put in column A. This will generate a price in H30 of sheet2 and I need it copied back to column H of the filtered row above.
CSS_quoting_tool_29.6.xlsm | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
A | B | C | D | E | F | G | H | |||
29 | Date | Service | Unit Price | Day rate | Hours | Staff Req. | Kms Travelled | Price ex. GST | ||
30 | 07/07/2020 | Supervised Transport | $55.80 | Business_day_rate | 3 | 1 | $167.40 | |||
Sheet2 |
Cell Formulas | ||
---|---|---|
Range | Formula | |
C30 | C30 | =IF([@Service]="Activities",[@Activities],INDEX(Service_Types,MATCH([@Service],Sheet2!$A$5:$A$12,0),MATCH([@[Day rate]],Sheet2!$A$5:$E$5,0))) |
D30 | D30 | =IF(A30="","",IF(COUNTIF(Sheet2!$G$87:$DO$97,A30),"Public_holiday",IF(WEEKDAY(A30)=1,"Sun",IF(WEEKDAY(A30)=7,"Sat","Business_day_rate")))) |
H30 | H30 | =IF([@Service]="Activities",ROUNDDOWN([@Activities]+[@[Transport $]],2),IF([@Service]="Carer Respite",[@[Staff Req.]]*[@Rate],ROUNDDOWN(((IF(OR(ISBLANK(A30),ISBLANK(D30),ISBLANK(B30)),0,[@[Transport $]]+[@MaxPay]))*[@[Staff Req.]]),2))) |
Named Ranges | ||
---|---|---|
Name | Refers To | Cells |
Service_Types | =Sheet2!$A$5:$E$12 | C30 |
Cells with Data Validation | ||
---|---|---|
Cell | Allow | Criteria |
A30 | Any value | |
B30 | List | =Service_List |
Can someone please help me with this code?