VBA to hide rows and copy values from 1 row to another sheet.

KyleJackMorrison

Board Regular
Joined
Dec 3, 2013
Messages
107
Office Version
  1. 365
  2. 2021
  3. 2019
Platform
  1. Windows
Hello,
i have a document i use for a FOE (forecast of events). It has each colleagues details on and the days which they are away. I use merged cells for blocking out more than 1 days worth of Task/Course.

What i need is a VBA to populate a weekly register to say whos here or not. It needs to read the cell which contains todays date (Mon 28/1/19) and populate the register with what activity they are on.

It's quite difficult to explain this however attached is a copy of my document and what i would like it to do.

I understand merged cells are a pain in the *** however i have found a manual way to do it!:

Hide every column apart from monday. Copy that column and paste onto work as a table. Copy that table and paste it into the register. This is the way to make it do what i would like. Just need to automate it.

Link:
https://www.dropbox.com/s/vozn3z3uwetw3gf/Public Document.xlsx?dl=0

Any help would be appreciated.

KJM
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
I give you the macro

Code:
Sub Button1_Click()
    Dim h1 As Worksheet, h2 As Worksheet
    Dim u2 As Long
    '
    Application.ScreenUpdating = False
    '
    Set h1 = Sheets("FOE")
    Set h2 = Sheets("REGISTER")
    '
    h2.Range("G4:T" & h2.Range("E" & Rows.Count).End(xlUp).Row).ClearContents
    u2 = h2.Range("E" & Rows.Count).End(xlUp).Row
    uc1 = h1.Cells(23, Columns.Count).End(xlToLeft).Column
    uc2 = h2.Cells(2, Columns.Count).End(xlToLeft).Column
    For i = 4 To u2
        surname = h2.Cells(i, "E").Value
        forename = h2.Cells(i, "F").Value
        Set r = h1.Columns("D")
        Set b = r.Find(surname, LookAt:=xlWhole)
        If Not b Is Nothing Then
            celda = b.Address
            Do
                'detalle
                If h1.Cells(b.Row, "E").Value = forename Then
                    For j = Columns("G").Column To uc2 Step 2
                        For k = Columns("J").Column To uc1
                            If h1.Cells(23, k).Value = h2.Cells(2, j).Value Then
                                If h1.Cells(b.Row, k).MergeCells Then
                                    activity = h1.Cells(b.Row, k).MergeArea.Cells(1, 1).Value
                                Else
                                    activity = h1.Cells(b.Row, k).Value
                                End If
                                If activity <> "" Then
                                    h2.Cells(i, j).Value = activity
                                End If
                            End If
                        Next
                    Next
                    Exit Do
                End If
                Set b = r.FindNext(b)
            Loop While Not b Is Nothing And b.Address <> celda
        End If
    Next
    Application.ScreenUpdating = True
    MsgBox "End"
End Sub
 
Upvote 0
@DanteAmor ,

Thank you ever so much! just what i needed and here's me thinking it'll be this massive code. Outstanding!

Have a good evening!
 
Upvote 0
I'm glad to help you. Thanks for the feedback.
 
Upvote 0
@DanteAmor

Hello, thanks for this code. However I am wondering whether it can be adapted so its finds Todays date on the "FOE" sheet and then use todays date cells to populate this weeks register?

SO i can use this each monday and it will populate each current weeks register.

TIA
 
Upvote 0

Forum statistics

Threads
1,215,440
Messages
6,124,882
Members
449,193
Latest member
PurplePlop

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top