SOLVED

Copy Data to Other Sheets' Columns Based on Values

Copper Contributor

Hi All,

 

I have been searching like crazy but struggling to find a solution that specifically fits what I am aiming to achieve.

 

First week of every month, I hope to walk into a patch-cycle meeting with an excel spreadsheet containing a list of servers. Next to that list of servers is another column with the 'week.day' so when we get the server owner to i.e. agree for patching on week 1 day 3 that column would have 1.3 populated in there.

 

WeekServ.jpg

Because of the nature that we perform our updates, I need another sheet to have headers for each of the 'Week' values (which can be pre-populated) and populate the cells below with each server that is marked for that week.

 

weekpln.jpg

I have tried using tools such as vlookup and some methods using =index but struggling to make any progress. I confess to being very new to complex Excel formulas so wondering if anyone has suggestions they could share?

 

I cannot deviate too greatly from the format above as it forms the basis of a macro-export to text file that I have which creates a text file per-week (based upon the header value) each of which contain the servers for that week/day. Any help would be greatly appreciated!

 

4 Replies
best response confirmed by WilderBog (Copper Contributor)
Solution

@WilderBog 

Hi,

you can do this with the following macro, see attachment.

 

Sub TransferData()
Dim lngRow As Long
Dim lngRowmax As Long
Dim rngFind As Range
Dim lngRowMaxT As Long

Sheet2.Range("A2:X" & Sheet2.Rows.Count).Clear

With Sheet1
lngRowmax = .Range("a" & .Rows.Count).End(xlUp).Row

For lngRow = 1 To lngRowmax

Set rngFind = Sheet2.Rows(1).Find(what:=.Range("A" & lngRow).Value, lookat:=xlWhole)
If Not rngFind Is Nothing Then
lngRowMaxT = Sheet2.Cells(Sheet2.Rows.Count, rngFind.Column).End(xlUp).Row + 1
Sheet2.Cells(lngRowMaxT, rngFind.Column).Value = .Range("B" & lngRow).Value

End If
Next lngRow

End With

End Sub

 

Best regards

Bernd

The vba-Tanker - a database full of macros

@WilderBog 

Variant with formulas for such sample

image.png

In I2

=IFERROR(INDEX(Table1[Week],AGGREGATE(15,6,1/(COUNTIF($H$2:H$2,Table1[Week])=0)*(ROW(Table1[Week])-ROW(Table1[[#Headers],[Week]])), 1 )),"")

and drag to the right till empty cells appear.

In I3

=IFERROR(INDEX(Table1[Server],AGGREGATE(15,6,1/(Table1[Week]=I$2)*(ROW(Table1[Week])-ROW(Table1[[#Headers],[Week]])),(ROW()-ROW(I$2)))),"")

and drag to the right and down.

 

If you have version of Excel with coming dynamic arrays, when

in E2

=TRANSPOSE(UNIQUE(Table1[Week]))

in E3

=FILTER(Table1[Server],Table1[Week]=E$2)

and drag to the right

@Berndvbatanker 

Exactly what I was looking for!

 

Thank you very much for this Bernd, that makes this process a great deal easier, now to apply your solution to my spreadsheet.

Hi Sergei,
Thank you for this, I was a little puzzled when I changed the 'week' number against Server1 and it broke the results but i suspect that is my fault in the way I have described the requirements.

The key identifier is the Server which i would usually have as a field to the left but because I was working with Vlookups i'd moved the 'Week' to the left column in order to allow vlookup to function properly.

Essentially, the result achieved by Bernd's method was spot on so i'll amalgamate his code into my spreadsheet but thank you for taking the time to help me!
1 best response

Accepted Solutions
best response confirmed by WilderBog (Copper Contributor)
Solution

@WilderBog 

Hi,

you can do this with the following macro, see attachment.

 

Sub TransferData()
Dim lngRow As Long
Dim lngRowmax As Long
Dim rngFind As Range
Dim lngRowMaxT As Long

Sheet2.Range("A2:X" & Sheet2.Rows.Count).Clear

With Sheet1
lngRowmax = .Range("a" & .Rows.Count).End(xlUp).Row

For lngRow = 1 To lngRowmax

Set rngFind = Sheet2.Rows(1).Find(what:=.Range("A" & lngRow).Value, lookat:=xlWhole)
If Not rngFind Is Nothing Then
lngRowMaxT = Sheet2.Cells(Sheet2.Rows.Count, rngFind.Column).End(xlUp).Row + 1
Sheet2.Cells(lngRowMaxT, rngFind.Column).Value = .Range("B" & lngRow).Value

End If
Next lngRow

End With

End Sub

 

Best regards

Bernd

The vba-Tanker - a database full of macros

View solution in original post