Trying to add 3 cells together with VBA

leopilot

New Member
Joined
Dec 24, 2014
Messages
12
So i have some cells that move around, but i can find them by referenceing something else. So i want to add these cells together. mnow here is my code. However i can not get excel to calculate it until i click on it. Any help?


Dim MS As String
Dim MSC As String
Dim MF As String
Dim ADD As String
With ActiveSheet.Range("A1:B500")
Set c = .Find("SAL MED SERV Total", LookIn:=xlValues)
If Not c Is Nothing Then
firstAddress = c.Address
Do
c.Offset(0, -1).Activate

Selection.Offset(0, 17).Select

MS = ActiveCell.Address

Set c = .FindNext(c)
Loop While Not c Is Nothing And c.Address <> firstAddress
End If
End With
With ActiveSheet.Range("A1:B500")
Set c = .Find("SAL MEDICAL ADMIN Total", LookIn:=xlValues)
If Not c Is Nothing Then
firstAddress = c.Address
Do
c.Offset(0, -1).Activate


Selection.Offset(0, 17).Select

MSC = ActiveCell.Address


Set c = .FindNext(c)
Loop While Not c Is Nothing And c.Address <> firstAddress
End If
End With

With ActiveSheet.Range("A1:B500")
Set c = .Find("SAL MED FACILITIES Total", LookIn:=xlValues)
If Not c Is Nothing Then
firstAddress = c.Address
Do
c.Offset(0, -1).Activate


Selection.Offset(0, 17).Select

MF = ActiveCell.Address

Set c = .FindNext(c)
Loop While Not c Is Nothing And c.Address <> firstAddress
End If
End With


With ActiveSheet.Range("A1:B500")
Set c = .Find("Grand Total", LookIn:=xlValues)
If Not c Is Nothing Then
firstAddress = c.Address
Do
c.Offset(0, 17).Activate


ActiveCell.Formula = MS & "+" & MF & "+" & MSC



Set c = .FindNext(c)
Loop While Not c Is Nothing And c.Address <> firstAddress
End If
End With
 
To return the address without the dollar signs, you can do it like this:
Code:
    MS = Replace(ActiveCell.Address, "$", "")
 
Upvote 0

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Gentlemen, I greatly appreciate your help. I would like to say you are all awesome and thank you again. It works... i have saved my self about 2 hours of mind numbing work every pay period.
 
Upvote 0

Forum statistics

Threads
1,216,115
Messages
6,128,915
Members
449,478
Latest member
Davenil

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