Rewriting each IF statement so that it is on a single line??

nV138

New Member
Joined
Feb 8, 2013
Messages
2
Hi, I have the following IF statement

If strMyOperation = "+" Then
Worksheets("Sheet1").Range("F10").Value = sngMy1stValue + sngMy2ndValue
End If

How can I write this on one single line

Putting "Worksheets("Sheet1").Range("F10").Value = sngMy1stValue + sngMy2ndValue End If right after the first statement does not work, any ideas??

would be very grateful
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
Welcome to the board..

If you put it on a single line, you don't need the End If

Try

If strMyOperation = "+" Then Worksheets("Sheet1").Range("F10").Value = sngMy1stValue + sngMy2ndValue
 
Upvote 0
Glad to help..

Note, that doesn't make your code any faster.
At least not to my knowledge..

Personally, I prefer to use the Block If Structure in longer more complicated codes.
It makes for easier reading in my opinion, particularly when you indent the If's and Loops and Withs..

Code:
If strMyOperation = "+" Then
    Worksheets("Sheet1").Range("F10").Value = sngMy1stValue + sngMy2ndValue
End If

The indents really make reading the code so much easier.
 
Upvote 0

Forum statistics

Threads
1,222,907
Messages
6,168,963
Members
452,228
Latest member
just4jeffrey

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