dreen
Board Regular
- Joined
- Nov 20, 2019
- Messages
- 52
I have two workbooks for my code, one is a database (The "Changes" sheet in my example) and the other is an input sheet "(Codename "Sheet1" as my code is being written inside this workbook where Sheet1 is). I am trying to have the code check if the value of certain cells in column "K' of Sheet 1 are equal to something (<>""), and if they are, I am trying to filter the "Changes" sheet to filter out which row in column A has the value of cell "H4" from Sheet1, so that I can copy and paste the value of "K30" from Sheet1 (from the workbook where the code is being written) into cell "F6" [cells (1,6)] of the other workbook (the "Changes" sheet)
VBA Code:
'Module 8: Sends the requested changes over to the "Changes" sheet
Sub SendChanges()
Set Cd = Workbooks.Open("\\FILEPATH\Changes_Database_IRR_20-2S_New.xlsm")
Set Changes = Cd.Sheets("Changes")
Changes.Activate
ActiveSheet.Unprotect "Swrf"
Sheet1.Unprotect "Swrf"
'Only executes this macro if the the new/change requested value in column "K" of the Operator sheet (Codename Sheet1) has a numerical value present
If Sheet1.Range("K30").Value <> "" Then
'Filters the Changes_Database for the part name & process (the key) which is in cell "H4" of the Operator sheet (Codename Sheet1)
Changes.Range("A1").AutoFilter Field:=1, Criteria1:=Sheet1.Range("H4")
'Copies the changed content in cell "K30" from the Operator Sheet (Codename Sheet1)
Sheet1.Range("K30").Copy
'Finds the row in the Changes_Database ("Changes" sheet) that has matched all filters and;
'Pastes the value of cell "K30" (From Codename "Sheet1" or Operator sheet) into the matching parameter cell in the Changes_Database,which is in column 6 in this case
Changes.AutoFilter.Range.Offset(1).SpecialCells(xlCellTypeVisible).Cells(1, 6).PasteSpecial xlPasteValues
'Removes all filters and shows all data'
Changes.ShowAllData
End If
ActiveSheet.Protect "Swrf"
ActiveWorkbook.Save
ActiveWorkbook.Close SaveChanges:=True
Sheet1.Protect "Swrf"
End Sub