Hello,
I am trying to tackle an idea I had for a macro. I'm very new to macros and have only created a few of them.
I have a list of dates from a 60 year time span. I have created a table, columns being years, rows being months and days. I want to read the list of dates I have then find that date in the table. Example, the list date is 1/3/1950; I need to find the 1/3 row and 1950 column and put a value of 1 in the cell. For all other dates not in the list I need values of 0.
My idea is to have the macro loop through the list. Each date it will read from the left to the second "/", and someone find the row corresponding to that date. Then it will read the first four digits from the right, and find the corresponding column. Where these two intersect, a value of 1 will be placed.
Is this possible, or am I getting way over my head?
Comments
Dim loX As Long
For Each obCurCell In Range("D371:D372")
For Each obCurCell2 In Range("C3:C367")
If obCurCell.Value = obCurCell2.Value Then
loX = obCurCell2.Row
Range("D" & loX) = 1
End If
Next
Next
End Sub[/code]
This code works for the first column. I need my obCurCell to loop from Column D to Column BK, and I need my obCurCell Range to loop from row 371 to 392.
[code]
For Each obCurCell In Range("D371:D372")
For Each obCurCell2 In Range("C3:C367")
If obCurCell.Value = obCurCell2.Value Then
loX = obCurCell2.Row
Range("D" & loX) = 1
End If
Next
Next
[/code]
Could be changed to:
[code]
Dim i As Integer, j As Integer
For i = 371 To 372
For j = 3 To 367
If Cells(i, 4).Value = Cells(j, 3).Value Then
Cells(j, 4).Value = 1
End If
Next
Next
[/code]
Then it's a simple case of changing those hard-coded numbers to variables too, i.e. instead of that 4 there, change it to a variable called k (or whatever you like) and put in another for loop of "for k = 4 to 63" (columns D to BK). HTH, if you have any questions, please ask. Regards, Dai
------------------------------------------
Do or do not, there is no try. |
------------------------------------------