Lord Bowler
New Member
- Joined
- Dec 16, 2009
- Messages
- 18
I'm working on automating a project. I have an excel template which matches our web form that I use to test the calculations in our online system and to test calc changes, "what ifs".
I extract the data set for all school districts state-wide and want to pull this information from this tab to my template tab via a macro automatically. I currently use an Index function to find the intersection of the District Code and the Reference Key.
I'm working on making a macro that will go down each row and pull the cell value after finding the intersection of the Row(District) and Column(RefKey) on my dataset tab.
I've got it working but it is clunky:
Sub Test()
Dim rows As Long
Dim cols As Long
Dim Refkey As String
Dim DistrictCode As String ' Gotten from cell that user types in.
DistrictCode = Range("D11").Value 'Will come from user input box.
Dim nrow As Long
nrow = 0
Do
Select Case Range("H15").Offset(nrow, 0).Value 'Initial row
Case "2009-10" ' Years are located in H.
' Set Refkey value without the # symbol
Refkey = Mid(Range("G15").Offset(nrow, 0).Text, 2)
' Get Row Location
rows = Application.WorksheetFunction.Match(DistrictCode, Sheets("2009-10").Range("A1:A750"), 0)
' Get Column Location
cols = Application.WorksheetFunction.Match(Refkey, Sheets("2009-10").Range("A5:DI5"), 0)
Range("I15").Offset(nrow, 0).Value = Sheets("2009-10").Cells(rows, cols).Value
Case Else
MsgBox "Else"
End Select
nrow = nrow + 1
Loop Until nrow = 40 'for testing purposes, will eventually go until last row.
End Sub
I've removed the other Case statements as I am using 3-4 datasets for various years.
Anyone know of a less clunky way to get the row and column offset?
Also, I need to trap for when a Refkey is not found easily and place a 0 or a note for testing purposes for cols=...
I will eventually be removing all cell refs and using relative locs so I can use this macro across all 20 template files that I have.
Thanks in advance.
I extract the data set for all school districts state-wide and want to pull this information from this tab to my template tab via a macro automatically. I currently use an Index function to find the intersection of the District Code and the Reference Key.
I'm working on making a macro that will go down each row and pull the cell value after finding the intersection of the Row(District) and Column(RefKey) on my dataset tab.
I've got it working but it is clunky:
Sub Test()
Dim rows As Long
Dim cols As Long
Dim Refkey As String
Dim DistrictCode As String ' Gotten from cell that user types in.
DistrictCode = Range("D11").Value 'Will come from user input box.
Dim nrow As Long
nrow = 0
Do
Select Case Range("H15").Offset(nrow, 0).Value 'Initial row
Case "2009-10" ' Years are located in H.
' Set Refkey value without the # symbol
Refkey = Mid(Range("G15").Offset(nrow, 0).Text, 2)
' Get Row Location
rows = Application.WorksheetFunction.Match(DistrictCode, Sheets("2009-10").Range("A1:A750"), 0)
' Get Column Location
cols = Application.WorksheetFunction.Match(Refkey, Sheets("2009-10").Range("A5:DI5"), 0)
Range("I15").Offset(nrow, 0).Value = Sheets("2009-10").Cells(rows, cols).Value
Case Else
MsgBox "Else"
End Select
nrow = nrow + 1
Loop Until nrow = 40 'for testing purposes, will eventually go until last row.
End Sub
I've removed the other Case statements as I am using 3-4 datasets for various years.
Anyone know of a less clunky way to get the row and column offset?
Also, I need to trap for when a Refkey is not found easily and place a 0 or a note for testing purposes for cols=...
I will eventually be removing all cell refs and using relative locs so I can use this macro across all 20 template files that I have.
Thanks in advance.