Totally new to VBA and I need help

Kazarak

New Member
Joined
Dec 27, 2018
Messages
2
I am working on an workbook that serves as a character sheet in a table top RPG that I play. I am trying to find a way to code the hit point functions in VBA so that I can enter numbers in three different cells and have the entered numbers subtract or add to other cells and then clear the field for another entry. One for taking damage, one for getting healed, and one for gaining temp HP. I realize some of this may be information you don't need to know but I feel like explaining what I want to accomplish is helpful. the code I have come up with so far is this:

Sub HitPointFunction()
If Worksheets("Main").Range("M29").Value = 0 Then
Worksheets("Main").Range("M29").Value -Range("I28").Value
Else
Worksheets("Main").Range("M29").Value -Range("I28").Value

End If
End Sub

I am just getting started on the attempt at coding this and quickly ran into problems. This doesn't work. It throws up run-time error 438: Object doesn't support this property or method. I realize this is basic code but I am not experienced in this at all. I am simply trying to learn through Google. I don't think this works conceptually or at least not the way I am writing it. I can attach the workbook if that would help just let me know
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Which cell are you trying to subtract from and which cell has the value you want to subtract?

If you wanted to subtract the value in I28 on the active sheet from the value in M29 on the sheet 'Main' this is how the code would look.
Code:
Sheets("Main").Range("M29").Value = Sheets("Main").Range("M29").Value - Range("I28").Value
 
Upvote 0
This is one of the parts I would like to do. I am hoping for it to be conditional. I want the value in I28 to be subtracted from M29 only if M29 has a value. If M29 has no value I would like it to be subracted from M24. This is the basis of what I'd like to do for the most part. I appreciate your help with this.
 
Upvote 0
For that, try this.
Code:
If Sheets("Main").Range("M29").Value > 0 Then
    Sheets("Main").Range("M29").Value = Sheets("Main").Range("M29").Value - Range("I28").Value
Else
    Sheets("Main").Range("M24").Value = Sheets("Main").Range("M24").Value - Range("I28").Value
End If
 
Upvote 0

Forum statistics

Threads
1,223,231
Messages
6,170,884
Members
452,364
Latest member
springate

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