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.

:roll:
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
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,222,319
Messages
6,165,307
Members
451,951
Latest member
brentcole

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