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.
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
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
 
Upvote 0

Forum statistics

Threads
1,215,746
Messages
6,126,643
Members
449,325
Latest member
Hardey6ix

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top