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: 39

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
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,223,886
Messages
6,175,196
Members
452,616
Latest member
intern444

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