Can someone help me with this macro?

lucasandrade05

New Member
Joined
Oct 9, 2014
Messages
1
Hi Guys,
I'm new here and I'm enjoying programming with VBA now.
I wanna do a macro that can sum about 40 numbers from the active cell to the top.
The macro will check If the cell is a number, sum, and after the total will get in bold.
If a number already is bold, the sum will stop and That number that was in bold now will change for normal.
But when I'm run the code, the word "IsNumeric" shows me a error.
I did this at now :

Dim a As Long
Dim b As Long
Dim d As Variant
Dim x As Integer


a = ActiveCell.Row
b = ActiveCell.Column
x = 0


For x = 1 To 40
If IsNumeric((Cells((a - x), b))) & Cells((a - x), b) <> "" Then​
If x = 1 Then​
d = Cells((a - x), b)​
Else​
d = Cells((a - x), b) + d​
If (Cells((a - x), b).Font.Bold) Then​
Cells((a - x), b).Font.Bold = False​
x = 40​
End If​
End If​
Else​
x = 40​
End If​
Next x
ActiveCell.Value = d
ActiveCell.Style = "total1"
End Sub



The error is in the line "If IsNumeric((Cells((a - x), b))) & Cells((a - x), b) <> "" Then"
But I dont know why, 'cause this have been working, and suddently stopped
Please help me :(

PS: Sorry for my bad english, I'm from Brazil.
 

Some videos you may like

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type

JoeMo

MrExcel MVP
Joined
May 26, 2009
Messages
17,206
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
Haven't looked at all your code, but you can remove the immediate error by changing this:

If IsNumeric((Cells((a - x), b))) & Cells((a - x), b) <> "" Then

to this:

If IsNumeric((Cells((a - x), b))) And Cells((a - x), b) <> "" Then
 

Watch MrExcel Video

Forum statistics

Threads
1,108,956
Messages
5,525,883
Members
409,669
Latest member
JDCupps

This Week's Hot Topics

Top