hellfire45
Active Member
- Joined
- Jun 7, 2014
- Messages
- 464
Hi guys,
If I have something like the below, that will loop through some rows on a spreadsheet. Say, I want to do this same type of operation on 4 or 5 spreadsheets. Rather than copy and paste this 5 times and just changing the WITH statement, can I create like a looping array that will let me only have the code once but then it loops and changes what is in the WITH?
Btw, for the With, I am using the "left worksheet name" in the VBA editor. Dunno what to call that but when you chance the name of the worksheet under properties. Does this make sense? Thanks so much!
If I have something like the below, that will loop through some rows on a spreadsheet. Say, I want to do this same type of operation on 4 or 5 spreadsheets. Rather than copy and paste this 5 times and just changing the WITH statement, can I create like a looping array that will let me only have the code once but then it loops and changes what is in the WITH?
Btw, for the With, I am using the "left worksheet name" in the VBA editor. Dunno what to call that but when you chance the name of the worksheet under properties. Does this make sense? Thanks so much!
VBA Code:
With Air
user_id = Application.Match("Reserved by ID", Air.Rows("1:1"), 0)
department = Application.Match("Department", Air.Rows("1:1"), 0)
tier2_man = Application.Match("Tier 2 Manager", Air.Rows("1:1"), 0)
lastrow = POD.Columns(POD_PO).Find("*", , , , xlRows, xlPrevious).Row
For x_row = 2 To lastrow
current_user = .Cells(x_row, user_id).Value
If IsError(Application.Index(map_index_range, Application.Match(current_user, map_match_range, 0), map_tier2_man)) Then
.Cells(x_row, tier2_man) = ""
Else
.Cells(x_row, tier2_man) = Application.Index(map_index_range, Application.Match(current_user, map_match_range, 0), map_tier2_man)
End If
If IsError(Application.Index(map_index_range, Application.Match(current_user, map_match_range, 0), map_department)) Then
.Cells(x_row, department) = ""
Else
.Cells(x_row, department) = Application.Index(map_index_range, Application.Match(current_user, map_match_range, 0), map_department)
End If
Next
End With