Creating a Simple macro

G

Gunti

Hi,
I want to create a very simple macro and i'm having trouble finding it on
the internet.

I basicly want the following formula:

If Range(a1) = "x" Then
Cell A2 = "Cell A3*0.5)

I am completely new to creating macro's (as you can see).
Any help is appreciated

Gunti
 
L

Luke M

Sub YourMacroName()
If Range("A1").Value = "x" Then
Range("A2").Value = Range("A3").Value * 0.5
End If
End Sub

Just paste then into a module in the VBA editor, and you should be good.
 
G

Gunti

Hi, Thanks alot. I have another question though, i want it to act exactly
like a normal Excel formula (monitor if A1="x" all the time)
 
J

John

Hi Gunti
I know your asking for a macro but a simple formula will do the same
=IF(A1="x",A3*0.5,"") if no"x" show nothing.
HTH
John
 
L

Luke M

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Range("A1").Value = "x" Then
Range("A2").Value = Range("A3").Value * 0.5
End If
End Sub

Note that you will need to paste this onto the correct sheet in VBA, NOT a
module.
 
G

Gunti

I know this, the reason i'm asking such a simple question is because i now
can modify the formula given to my needs (I don't want the formula part in
excel to be filled).

Grtz & Thanks,
Gunti
 
G

Gunti

Hey, thanks alot! Almost exactly what i need. Now i need one last thing, how
do i use this for multiple cells. Do i add a new Private Sub?

Thanks a lot!
 
G

Gunti

Another question, this works. It however waits for me to click somewhere in
the sheet before it changes my cell. Any way to avoid this?

Greets,
Gunti
 
G

Gunti

Wow @ replying 3 times. I'm sorry.

I however found it necessary that i'm using the following formula:

If Range("D32").Value = "All-in 10%" Then
Range("D33").Value = Range("N5").Value

Another quick one while i'm at it:
I want it to become empty when it is not "All-in 10%".

If Range("D32").Value = "All-in 10%" Then
Range("D33").Value = Range("N5").Value
Then
Range("D33").Value = ??????

What must i use for it to become empty??
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top