Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
Tdp Tdp is offline
external usenet poster
 
Posts: 74
Default Code to multiply two cells?

How do I write
D4=E4*F4
as a vb code
--
Tdp
  #2   Report Post  
Excel Super Guru
 
Posts: 1,867
Thumbs up Answer: Code to multiply two cells?

To write the code to multiply two cells in Excel using VBA, you can use the following code:

Formula:
Range("D4").Value Range("E4").Value Range("F4").Value 
This code will multiply the values in cells E4 and F4 and then store the result in cell D4.

Here's a step-by-step guide on how to write this code:
  1. Open the Excel workbook where you want to write the code.
  2. Press ALT + F11 to open the VBA editor.
  3. In the VBA editor, click on Insert Module to create a new module.
  4. In the new module, type the following code:

    Formula:
    Sub MultiplyCells()
        
    Range("D4").Value Range("E4").Value Range("F4").Value
    End Sub 
  5. Save the module and close the VBA editor.
  6. Go back to the Excel workbook and select the cell where you want to run the code (e.g. D4).
  7. Press ALT + F8 to open the Macro dialog box.
  8. Select the MultiplyCells macro and click on Run.
  9. The code will run and the result of the multiplication will be displayed in cell D4.

That's it! You have now written a VBA code to multiply two cells in Excel.
__________________
I am not human. I am an Excel Wizard
  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3,365
Default Code to multiply two cells?

Range("D4") = Range("E4")*Range("F4")


"Tdp" wrote:

How do I write
D4=E4*F4
as a vb code
--
Tdp

  #4   Report Post  
Posted to microsoft.public.excel.misc
Tdp Tdp is offline
external usenet poster
 
Posts: 74
Default Code to multiply two cells?

Thanks for that J.
I assume if it`s in sheet4 then I write
Worksheets("Sheet4").Range("D4") = Range("E4")*Range("F4")
?
--
Tdp


"JLatham" wrote:

Range("D4") = Range("E4")*Range("F4")


"Tdp" wrote:

How do I write
D4=E4*F4
as a vb code
--
Tdp

  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,058
Default Code to multiply two cells?

You can qualify all the pieces:

Sub dural()
With Worksheets("Sheet4")
..Range("D4") = .Range("E4") * .Range("F4")
End With
End Sub

--
Gary''s Student - gsnu200808


"Tdp" wrote:

Thanks for that J.
I assume if it`s in sheet4 then I write
Worksheets("Sheet4").Range("D4") = Range("E4")*Range("F4")
?
--
Tdp


"JLatham" wrote:

Range("D4") = Range("E4")*Range("F4")


"Tdp" wrote:

How do I write
D4=E4*F4
as a vb code
--
Tdp



  #6   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3,365
Default Code to multiply two cells?

As I wrote it, it would automatically apply to the "active sheet".

But since you may want it to go to another sheet, then the way you wrote it
would work. Might have to treat the E4 and F4 references the same way also,
i.e. specifically referencing the worksheet(s) they are on also.

Other than taking a little extra time to resolve the location, it never
hurts to use the worksheet name along with the address; and sometimes it is a
must do.

"Tdp" wrote:

Thanks for that J.
I assume if it`s in sheet4 then I write
Worksheets("Sheet4").Range("D4") = Range("E4")*Range("F4")
?
--
Tdp


"JLatham" wrote:

Range("D4") = Range("E4")*Range("F4")


"Tdp" wrote:

How do I write
D4=E4*F4
as a vb code
--
Tdp

  #7   Report Post  
Posted to microsoft.public.excel.misc
Tdp Tdp is offline
external usenet poster
 
Posts: 74
Default Code to multiply two cells?

Thank you both. very useful
--
Tdp


"JLatham" wrote:

As I wrote it, it would automatically apply to the "active sheet".

But since you may want it to go to another sheet, then the way you wrote it
would work. Might have to treat the E4 and F4 references the same way also,
i.e. specifically referencing the worksheet(s) they are on also.

Other than taking a little extra time to resolve the location, it never
hurts to use the worksheet name along with the address; and sometimes it is a
must do.

"Tdp" wrote:

Thanks for that J.
I assume if it`s in sheet4 then I write
Worksheets("Sheet4").Range("D4") = Range("E4")*Range("F4")
?
--
Tdp


"JLatham" wrote:

Range("D4") = Range("E4")*Range("F4")


"Tdp" wrote:

How do I write
D4=E4*F4
as a vb code
--
Tdp

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
formula for multiply one cell to one of two other cells? M.Rafat Excel Discussion (Misc queries) 6 April 13th 07 07:02 AM
sum cells with color and multiply tmirelle Excel Discussion (Misc queries) 3 January 31st 07 11:19 AM
HOW TO MULTIPLY 2 CELLS THAT CONTAIN FORMULAS Kim Excel Discussion (Misc queries) 2 December 13th 06 04:34 PM
add value of 4 cells, multiply by 3 subtract 72 multiply by 80% George A. Yorks Excel Discussion (Misc queries) 10 October 25th 06 09:45 PM
is there a function that will multiply different cells Huck Excel Worksheet Functions 4 March 6th 06 09:41 PM


All times are GMT +1. The time now is 11:12 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"