fwoolston
03-13-2003, 11:13 AM
Hi,
I have been thrown into the fire to correct this code. Being a novice programmer at best, please be gentle. On the up side since the code has worked for the past 12 months and no changes have been made it should be an easy fix. So here is my problem.
I have an VB macro in Excel which reformats a txt report (created from our accounting system) that is giving the following error when ran:
"Method Range' of object'_Global' failed”. Debugger is highlighting the line range(strRange).Select with curser at beginning of line. I've found if I manually delete the last two rows in the unformatted spreadsheet, which is junk data, it runs without error. However since the code is programmed to delete last two lines this erases two lines of good data.
Here is the complete sub routine of question.
Private Sub FormatTotalLines()
Dim x As Long
Dim lngRow As Long
Dim strRange As String
Dim sJobCode As String
For x = 1 To MyTotalRows.Count
lngRow = MyTotalRows.Item(x).TotalRow
strRange = "A" & CStr(lngRow) & ":" & "AA" & CStr(lngRow)
range(strRange).Select
TotalLineCells
MyTotalRows.Item(x).ColTotals
sJobCode = range("C" & CStr(lngRow - 1)).Value
range("B" & CStr(lngRow)).Value = "Sub-Total for " & sJobCode
range("B" & CStr(lngRow)).Font.Bold = True
Next
End Sub
What does "Method Range' of object'_Global' failed" mean and any suggestions to resolve would be greatly appreciated.
Thanks in advance
I have been thrown into the fire to correct this code. Being a novice programmer at best, please be gentle. On the up side since the code has worked for the past 12 months and no changes have been made it should be an easy fix. So here is my problem.
I have an VB macro in Excel which reformats a txt report (created from our accounting system) that is giving the following error when ran:
"Method Range' of object'_Global' failed”. Debugger is highlighting the line range(strRange).Select with curser at beginning of line. I've found if I manually delete the last two rows in the unformatted spreadsheet, which is junk data, it runs without error. However since the code is programmed to delete last two lines this erases two lines of good data.
Here is the complete sub routine of question.
Private Sub FormatTotalLines()
Dim x As Long
Dim lngRow As Long
Dim strRange As String
Dim sJobCode As String
For x = 1 To MyTotalRows.Count
lngRow = MyTotalRows.Item(x).TotalRow
strRange = "A" & CStr(lngRow) & ":" & "AA" & CStr(lngRow)
range(strRange).Select
TotalLineCells
MyTotalRows.Item(x).ColTotals
sJobCode = range("C" & CStr(lngRow - 1)).Value
range("B" & CStr(lngRow)).Value = "Sub-Total for " & sJobCode
range("B" & CStr(lngRow)).Font.Bold = True
Next
End Sub
What does "Method Range' of object'_Global' failed" mean and any suggestions to resolve would be greatly appreciated.
Thanks in advance