- Nov 6, 2004
- 324
- 0
- 0
I'm trying to add some automation to an excel file we use in our office. Basically when you press the hotkey a red 'd/c' is added to the selected cell (this part works). But it's also supposed to change the contents of a different cell (in column I) to a red 'Yes-' concatenated with the contents from column D.
The red d/c appears correctly, but I get the following error:
Runtime error 1004:
Method 'Range' of object '_Global' failed
Here's the code (Sorry attach code not displaying it right):
Sub proDischarge()
Const LOC_COL As Integer = 4 ' Column D
Const DISCH_COL As Integer = 9 ' Column I
Const DAY1 As Integer = 15
Const DAY31 As Integer = 45
Dim rw As Integer
Dim col As Integer
rw = ActiveCell.Row ' The row of the selected cell
col = ActiveCell.Column ' Column of the selected cell
' Testing that active cell is in legal range (O - AS)
If rw = 1 Or (col < DAY1 Or col > DAY31) Then
MsgBox "Illegal cell"
Exit Sub
End If
' This bit adds the red 'd/c' to the selected cell after pressing the hotkey combination
Selection.Font.ColorIndex = 3
ActiveCell.Value = "d/c"
' Change text in 'Disch?' cell to red Yes and concatenate with contents of column D
Range(Cells(rw, DISCH_COL)).Font.ColorIndex = 3
Range(Cells(rw, DISCH_COL)).Value = "Yes-" & Range(Cells(rw, LOC_COL)).Value
End Sub
I have gone to the following link and followed the instructions there to no avail:
Solution from Microsoft
I have also done some googling that did not resolve the problem. Thanks for the help, I'm pretty new to VBA
The red d/c appears correctly, but I get the following error:
Runtime error 1004:
Method 'Range' of object '_Global' failed
Here's the code (Sorry attach code not displaying it right):
Sub proDischarge()
Const LOC_COL As Integer = 4 ' Column D
Const DISCH_COL As Integer = 9 ' Column I
Const DAY1 As Integer = 15
Const DAY31 As Integer = 45
Dim rw As Integer
Dim col As Integer
rw = ActiveCell.Row ' The row of the selected cell
col = ActiveCell.Column ' Column of the selected cell
' Testing that active cell is in legal range (O - AS)
If rw = 1 Or (col < DAY1 Or col > DAY31) Then
MsgBox "Illegal cell"
Exit Sub
End If
' This bit adds the red 'd/c' to the selected cell after pressing the hotkey combination
Selection.Font.ColorIndex = 3
ActiveCell.Value = "d/c"
' Change text in 'Disch?' cell to red Yes and concatenate with contents of column D
Range(Cells(rw, DISCH_COL)).Font.ColorIndex = 3
Range(Cells(rw, DISCH_COL)).Value = "Yes-" & Range(Cells(rw, LOC_COL)).Value
End Sub
I have gone to the following link and followed the instructions there to no avail:
Solution from Microsoft
I have also done some googling that did not resolve the problem. Thanks for the help, I'm pretty new to VBA
