Excel vba code for adding a value to existing cell of sheet
I have this code to add value of a cell to an existing value of the other cell:
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
If Not (Intersect(Target, Range("E3")) Is Nothing) Then
Range("F3").Value = Range("E3").Value + Range("F3").Value
End If
End Sub
But my problem is it just work in one cell, but not in a row, that is e. g. I want to add up B1
value to A1
existing value. It works OK, but i have 24 rows, that is B2
to A2
it don't work I don't want to add them combine but separably B2
to A2
and B3
to A3
this way 24 times.
Please help, it's urgent.
microsoft-excel vba cells
add a comment |
I have this code to add value of a cell to an existing value of the other cell:
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
If Not (Intersect(Target, Range("E3")) Is Nothing) Then
Range("F3").Value = Range("E3").Value + Range("F3").Value
End If
End Sub
But my problem is it just work in one cell, but not in a row, that is e. g. I want to add up B1
value to A1
existing value. It works OK, but i have 24 rows, that is B2
to A2
it don't work I don't want to add them combine but separably B2
to A2
and B3
to A3
this way 24 times.
Please help, it's urgent.
microsoft-excel vba cells
What? All this does is add E3 to F3 if your changed E3? I don't understand your question.
– Raystafarian
Feb 12 '14 at 18:34
add a comment |
I have this code to add value of a cell to an existing value of the other cell:
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
If Not (Intersect(Target, Range("E3")) Is Nothing) Then
Range("F3").Value = Range("E3").Value + Range("F3").Value
End If
End Sub
But my problem is it just work in one cell, but not in a row, that is e. g. I want to add up B1
value to A1
existing value. It works OK, but i have 24 rows, that is B2
to A2
it don't work I don't want to add them combine but separably B2
to A2
and B3
to A3
this way 24 times.
Please help, it's urgent.
microsoft-excel vba cells
I have this code to add value of a cell to an existing value of the other cell:
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
If Not (Intersect(Target, Range("E3")) Is Nothing) Then
Range("F3").Value = Range("E3").Value + Range("F3").Value
End If
End Sub
But my problem is it just work in one cell, but not in a row, that is e. g. I want to add up B1
value to A1
existing value. It works OK, but i have 24 rows, that is B2
to A2
it don't work I don't want to add them combine but separably B2
to A2
and B3
to A3
this way 24 times.
Please help, it's urgent.
microsoft-excel vba cells
microsoft-excel vba cells
edited Jan 18 at 13:37
MarianD
1,4111518
1,4111518
asked Feb 12 '14 at 18:06
user299606
1111
1111
What? All this does is add E3 to F3 if your changed E3? I don't understand your question.
– Raystafarian
Feb 12 '14 at 18:34
add a comment |
What? All this does is add E3 to F3 if your changed E3? I don't understand your question.
– Raystafarian
Feb 12 '14 at 18:34
What? All this does is add E3 to F3 if your changed E3? I don't understand your question.
– Raystafarian
Feb 12 '14 at 18:34
What? All this does is add E3 to F3 if your changed E3? I don't understand your question.
– Raystafarian
Feb 12 '14 at 18:34
add a comment |
1 Answer
1
active
oldest
votes
Does it have to be vba?
If you select column B copy (ctrl+c) then select column A and goto paste special you can use the add operator to do what you want.
Otherwise this function would work everytime you change a cell in column B it would update column A as column A+column B (for the specific row).
Gordon
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Dim int_range As Range
Set int_range = Intersect(Target, Range("B:B"))
If Not (int_range Is Nothing) Then
For Each c In int_range
c.Offset(0, -1).Value = c.Offset(0, -1).Value + c.Value
Next
End If
End Sub
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "3"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f715977%2fexcel-vba-code-for-adding-a-value-to-existing-cell-of-sheet%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Does it have to be vba?
If you select column B copy (ctrl+c) then select column A and goto paste special you can use the add operator to do what you want.
Otherwise this function would work everytime you change a cell in column B it would update column A as column A+column B (for the specific row).
Gordon
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Dim int_range As Range
Set int_range = Intersect(Target, Range("B:B"))
If Not (int_range Is Nothing) Then
For Each c In int_range
c.Offset(0, -1).Value = c.Offset(0, -1).Value + c.Value
Next
End If
End Sub
add a comment |
Does it have to be vba?
If you select column B copy (ctrl+c) then select column A and goto paste special you can use the add operator to do what you want.
Otherwise this function would work everytime you change a cell in column B it would update column A as column A+column B (for the specific row).
Gordon
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Dim int_range As Range
Set int_range = Intersect(Target, Range("B:B"))
If Not (int_range Is Nothing) Then
For Each c In int_range
c.Offset(0, -1).Value = c.Offset(0, -1).Value + c.Value
Next
End If
End Sub
add a comment |
Does it have to be vba?
If you select column B copy (ctrl+c) then select column A and goto paste special you can use the add operator to do what you want.
Otherwise this function would work everytime you change a cell in column B it would update column A as column A+column B (for the specific row).
Gordon
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Dim int_range As Range
Set int_range = Intersect(Target, Range("B:B"))
If Not (int_range Is Nothing) Then
For Each c In int_range
c.Offset(0, -1).Value = c.Offset(0, -1).Value + c.Value
Next
End If
End Sub
Does it have to be vba?
If you select column B copy (ctrl+c) then select column A and goto paste special you can use the add operator to do what you want.
Otherwise this function would work everytime you change a cell in column B it would update column A as column A+column B (for the specific row).
Gordon
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Dim int_range As Range
Set int_range = Intersect(Target, Range("B:B"))
If Not (int_range Is Nothing) Then
For Each c In int_range
c.Offset(0, -1).Value = c.Offset(0, -1).Value + c.Value
Next
End If
End Sub
answered Feb 12 '14 at 20:57
gtwebb
2,7871713
2,7871713
add a comment |
add a comment |
Thanks for contributing an answer to Super User!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f715977%2fexcel-vba-code-for-adding-a-value-to-existing-cell-of-sheet%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
What? All this does is add E3 to F3 if your changed E3? I don't understand your question.
– Raystafarian
Feb 12 '14 at 18:34