ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Macro question (https://www.excelbanter.com/excel-programming/423974-macro-question.html)

richzip

Macro question
 
I would like to know if a macro can accomplish the following: I have a large
worksheet with about 600 employees, and each employee has at least 1 row for
each date of the month.

For each employee, I would like to search in Column C for one of 2 different
values (RSV, NEW). If that value is found in ANY row for that employee, it
will copy all values in column C (for that employee) to the corresponding row
in column D.

Please see first reply for an example.

Don Guillett

Macro question
 
You could use a FINDNEXT macro(look in the vba help for FINDNEXT) to do just
that

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"richzip" wrote in message
...
I would like to know if a macro can accomplish the following: I have a
large
worksheet with about 600 employees, and each employee has at least 1 row
for
each date of the month.

For each employee, I would like to search in Column C for one of 2
different
values (RSV, NEW). If that value is found in ANY row for that employee,
it
will copy all values in column C (for that employee) to the corresponding
row
in column D.

Please see first reply for an example.



joel

Macro question
 
Try this code. It uses Sumproduct on the worksheet

Sub copycolumn()

OldEmployee = 0
RowCount = 1
Start = RowCount
CopyCol = False
Do While Range("A" & RowCount) < ""
If Range("A" & RowCount) < Range("A" & (RowCount + 1)) Then
Employee = Range("A" & RowCount)
ColARange = "A" & Start & ":A" & RowCount
ColCRange = "C" & Start & ":C" & RowCount

RSVSumProduct = "Sumproduct(--(" & ColARange & "=" & Employee & ")," & _
"--(" & ColCRange & "=""RSV""))"

RSVResult = Evaluate(RSVSumProduct)

NewSumProduct = "Sumproduct(--(" & ColARange & "=" & Employee & ")," & _
"--(" & ColCRange & "=""NEW""))"

NewResult = Evaluate(NewSumProduct)

Result = RSVResult + NewResult

If Result 0 Then
Range(ColCRange).Copy Destination:=Range("D" & Start)
End If

Start = RowCount + 1
End If
RowCount = RowCount + 1
Loop
End Sub


"Don Guillett" wrote:

You could use a FINDNEXT macro(look in the vba help for FINDNEXT) to do just
that

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"richzip" wrote in message
...
I would like to know if a macro can accomplish the following: I have a
large
worksheet with about 600 employees, and each employee has at least 1 row
for
each date of the month.

For each employee, I would like to search in Column C for one of 2
different
values (RSV, NEW). If that value is found in ANY row for that employee,
it
will copy all values in column C (for that employee) to the corresponding
row
in column D.

Please see first reply for an example.





All times are GMT +1. The time now is 06:39 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com