Cells() value holding

masarup11

New Member
Joined
Oct 2, 2017
Messages
9
Is there any way that i could store the value of

Code:
Dim num as Double
num = Cells(x,1) - Cells(x,2)


i'm kinda new to excel vba so im not sure if there's another way around this code

TIA..
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
What's the problem exactly? That code is perfectly valid as long as x is a valid value and both cells are numeric.
 
Upvote 0
You may think that, but it is valid, subject to the items I mentioned. What is the full code, what is the error, and what is in the cells in question when the error occurs?
 
Upvote 0
You may think that, but it is valid, subject to the items I mentioned. What is the full code, what is the error, and what is in the cells in question when the error occurs?

well i got a little. but i still have a problem, yes it's computing but it only computes for Range("A1") + Range("B1")
 
Upvote 0
If x = 1 then it will subtract B1 from A1. If x has another value it will subtract Bx from Ax. You still have not explained what your problem is.
 
Upvote 0
If x = 1 then it will subtract B1 from A1. If x has another value it will subtract Bx from Ax. You still have not explained what your problem is.

i need to automatically compute other rows for example

Code:
Cells(x,5) = Cells(x,1) -

is there anyway to do this? heres my code

Code:
Dim numbers(), arrItem, maxItem, result, searchNum
Dim x As Integer
x = 1
    searchNum = Cells(x, 1) - Cells(x, 2)            'search number
    numbers = Array(1, 3125, 3542, 4375, 6042, 8958, 13542, 23958)
    maxItem = Application.Max(numbers)      'get max of array item
    For Each arrItem In numbers             'loop through each array item
    
        If Abs(searchNum - arrItem) < maxItem Then
            maxItem = Abs(searchNum - arrItem)
            result = arrItem
        End If
    Next arrItem
    
    Cells(x, 7) = searchNum - Results
 
Upvote 0
We don't delete threads. It would be nice if you posted your solution for the benefit of others who may come looking for something similar later.
 
Upvote 0

Forum statistics

Threads
1,224,828
Messages
6,181,215
Members
453,024
Latest member
Wingit77

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