Excelquestion35
Board Regular
- Joined
- Nov 29, 2021
- Messages
- 53
- Office Version
- 2016
- Platform
- Windows
Hi all,
Currently I am looking for a way to find a certain that is a header (first row, one of the columns).
In the code below, the following process is done:
Your help is much appreciated!
Currently I am looking for a way to find a certain that is a header (first row, one of the columns).
In the code below, the following process is done:
- Filter a worksheet by a Customer (As a String)
- Copy only column C of the filtered cells (list of managers)
- Paste these cells in A2 in the tgt Workbook.
- How do I find the corresponding customer in the tgt Workbook, thus replace value A2 by the Customer As a string?
To give you an idea, in the tgt Workbook every first cell of a column contains one of the customers (A1, B1 etc.) . Below this first cell is the list of managers that I want replaced.
My code should replace the list of managers by the managers of the corresponding customer. - The current code does not keep in mind the length of the list of mangers. E.g. The list of managers that I copy can be shorter than that is currently the case and thus not removes any obsolete manager.
How do I make sure that before I copy, I remove the list of current managers (e.g. G2:last row) for this specific Customer (As a String) where I am currently replacing the managers of?
VBA Code:
Sub Replacetext()
Dim src As Worksheet
Dim tgt As Worksheet
Dim filterRange As Range
Dim copyRange As Range
Dim lastRow As Long
Dim customer As String
Set src = Workbooks("Copy of Site overview (003) - 2.xlsm").Sheets("FLMs")
Set tgt = Workbooks("Kronos Centraal Formulier v3.2 - Template (zonder check) - RPA versie.xlsm").Sheets("Supervisor (leidinggevende)")
customer = Workbooks("Copy of Site overview (003) - 2.xlsm").Sheets("FLM-change").Range("C17")
src.AutoFilterMode = False
lastRow = src.Range("C" & src.Rows.Count).End(xlUp).Row
Set filterRange = src.Range("B3:P" & lastRow)
Set copyRange = src.Range("C4:C" & lastRow)
filterRange.AutoFilter field:=1, Criteria1:=customer
copyRange.SpecialCells(xlCellTypeVisible).Copy tgt.Range("A2")
End Sub
Your help is much appreciated!