HELP!!! IF THEN STATEMENT - VISUAL BASIC

mags74

New Member
Joined
Jul 19, 2007
Messages
7
Is it possible to do something within visual basic to say ==

if A1 = "Hello"
Then B2= "World"


but i want to be able to edit B2 = so if it says "World" - I can type in something after it or within B2 it can be edited.

I have tried doing Outstring but can not figure out how to do it at a range.

Please help...

Hope this makes sense.

:rolleyes:
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
Try

Code:
Sub test()
If Range("A1").Value = "Hello" Then Range("B2").Value = "World"
End Sub
 
Upvote 0
Welcome to the Board.

Like this?

Code:
If Range("A2").Value = "Hello" Then
   Range("B2").Value = WorksheetFunction.Substitute(Range("B2").Value,"World","World Peace")
End If
 
Upvote 0
Thank you.

I am not able to edit the "World" though. I would like to be able to edit it if needed within the cell.
 
Upvote 0
thank you mr. poulsom

for some reason i am not able to get that to work. it does not fill in the cell with world or world peace.

and thank you for the welcome. this is pretty neat i must say.
 
Upvote 0
You can't edit a cell while a VBA procedure is running. But you can use the InputBox function to prompt for a value and put it in a cell.
 
Upvote 0
thank you mr. poulsom

for some reason i am not able to get that to work. it does not fill in the cell with world or world peace.

and thank you for the welcome. this is pretty neat i must say.

The code I posted replaces the word World with World Peace if B2 already contains it.

Maybe you want:

Code:
If Range("A2").Value = "Hello" Then 
   If Instr(1,Range("B2").Value,"World") > 0 Then
      Range("B2").Value = WorksheetFunction.Substitute(Range("B2").Value,"World","World Peace") 
   Else
      Range("B2").Value = Range("B2").Value & " World"
   End If
End If
 
Upvote 0

Forum statistics

Threads
1,213,559
Messages
6,114,302
Members
448,564
Latest member
ED38

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