VBA code to loop and extract data

ten1jmj

New Member
Joined
Jan 10, 2019
Messages
7
I have another sheet were a user selects a name. Is it possible to have a macro loop through the data and return the event type listed below the employee along with the date. This is just a snippet of the data. An employee will have multiple event types. I'm not sure if this is even possible with my current data arrangement. Any help would be greatly appreciated.
 

Attachments

  • Screenshot_2020-03-26-07-24-02.png
    Screenshot_2020-03-26-07-24-02.png
    120 KB · Views: 35

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Assign a range name to the row with the names in it, eg NameRowRange

VBA Code:
Dim NameColumn as Integer
Dim RowCounter as Integer
Dim EventType as String

'Use Range.Find to identify the column the selected name is in
NameColumn = Range("NameRowRange").Find (<reference>)

'Search for a non-blank cell in the identified column
RowCounter = Range("NameRowRange).Row+1
While Len(Cells(RowCounter, NameColumn)) = 0 and RowCounter <=Range("NameRowRange).Row+100 '(or however many rows there are)
  EventType = Cells(RowCounter, NameColumn)
  RowCounter = RowCounter + 1
Wend

'The While/Wend loop will exit when Cells(RowCounter, NameColumn) has a length greater than zero.

'Then do something with EventType
 
Last edited by a moderator:
Upvote 0

Forum statistics

Threads
1,215,028
Messages
6,122,749
Members
449,094
Latest member
dsharae57

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