Thanks Ryan for your time. I was away so only last night I adapted your code to my project and when debugging I get a compile error message referring to GetRow at this point in code:
EnterRow=GetRow
The error says: "Wrong number of arguments or invalide property assignment.
I also have a question; what is EnterRow?
Also I do not know if it counts but the name of the months are in the date format (MMM); in B1 JAN I have this formula =DATE(YEAR($C$8),1,1), in C1 for FEB I have =DATE(YEAR($C$8),2,1), and in $C$8 I enter every month, the reporting month as date 06/01/2000 and is in (MMMM) format.
Thank you again for your time.
Sub EnterinHours() Dim LastRow As Long Dim MonthRow As String MonthRow = GetMonthRow(Cells(1, 15).Value) On Error Resume Next Application.ScreenUpdating = False EnterRow = GetRow(Cells(x, 14).Text) If EnterRow = "" Then Call EnterNewAcct(Cells(x, 14).Text) EnterRow = GetRow(Cells(x, 14).Text) End If Cells(EnterRow, MonthRow).Value = Cells(x, 15).Value Next x Function GetRow(Acct) Dim Cell As Range For Each Cell In Range("A2:A" & Range("A65000").End(xlUp).Row) If Cell.Text = "" Then Exit For If Mid(Cell.Value, InStr(1, Cell.Value, "(") + 1, _ InStr(InStr(1, Cell.Value, "(") + 1, Cell.Value, ")") _ - InStr(1, Cell.Value, "(") - 1) = Acct Then GetRow = Cell.Row Exit For End If Next Cell End Function Function GetMonthRow(Month) Dim x As Integer If Cells(1, x).Value = Month Then GetMonthRow = x Exit For End If Next x End Function Sub EnterNewAcct(Acct) Dim AcctName As String AcctName = InputBox("Please enter a name for account " & Acct, "Enter Account") If AcctName = "" Then Exit Sub Cells(Range("A65000").End(xlUp).Row + 1, 1).Value = AcctName & " (" & Acct & ")" For x = 2 To 13 Cells(Range("A65000").End(xlUp).Row, x).Value = 0 Next x
Felicia,
Is all this information on one sheet. For example, column A contains all the accounts, column B - M contain the months, column N contains the acct numbers to be inputed and column O contains the hours to be inputed? I wrote code to do what you need, but need to make sure where all your info is.
Ryan
Yes Ryan all are on one sheet thank you so much
Yes all are on one sheet.
Re: Yes Ryan all are on one sheet thank you so much
Felicia,
This code assumes everything I asked you before. Once you have the acct numbers entered in and the hours entered in, run this macro and all will be done. If there is a new account number, an Input Box will pop up asking you for the name of the new account. There is no need to put in the 3 numbers, for the program will put them in, just enter in the name. If there is something else let me know. Let me know how it works!
Ryan
Sub EnterinHours()
Dim LastRow As Long
Dim MonthRow As String
LastRow = Range("N65000").End(xlUp).Row
MonthRow = GetMonthRow(Cells(1, 15).Value)
On Error Resume Next
Application.ScreenUpdating = False
For x = 2 To LastRow
EnterRow = GetRow(Cells(x, 14).Text)
If EnterRow = "" Then
Call EnterNewAcct(Cells(x, 14).Text)
EnterRow = GetRow(Cells(x, 14).Text)
End If
Cells(EnterRow, MonthRow).Value = Cells(x, 15).Value
Next x
Application.ScreenUpdating = True
End Sub
Function GetRow(Acct)
Dim Cell As Range
For Each Cell In Range("A2:A" & Range("A65000").End(xlUp).Row)
If Cell.Text = "" Then Exit For
If Mid(Cell.Value, InStr(1, Cell.Value, "(") + 1, _
InStr(InStr(1, Cell.Value, "(") + 1, Cell.Value, ")") _
- InStr(1, Cell.Value, "(") - 1) = Acct Then
GetRow = Cell.Row
Exit For
End If
Next Cell
End Function
Function GetMonthRow(Month)
Dim x As Integer
For x = 2 To 13
If Cells(1, x).Value = Month Then
GetMonthRow = x
Exit For
End If
Next x
End Function
Sub EnterNewAcct(Acct)
Dim AcctName As String
AcctName = InputBox("Please enter a name for account " & Acct, "Enter Account")
If AcctName = "" Then Exit Sub
Cells(Range("A65000").End(xlUp).Row + 1, 1).Value = AcctName & " (" & Acct & ")"
For x = 2 To 13
Cells(Range("A65000").End(xlUp).Row, x).Value = 0
Next x
End Sub