Inserting text using VBA

WuAhUuU

Board Regular
Joined
Sep 16, 2008
Messages
66
I am creating a macro where depending on the day of the year, it will either be OPEN or CLOSE...

However, I would like to know how can the words OPEN or CLOSE be inserted by the macro.

Example of the code:
Rich (BB code):
Private Sub cmdcancel_Click()
    Unload Me
End Sub
 
Private Sub cmdinsert_Click()
Set portugal = Worksheets("PORTUGAL")
Set priv= Worksheets("PRIVATE")
Set param= Worksheets("PARAMETERS")
 
Application.ScreenUpdating = False
 
If txtdate = "" Then
msg = "Please be sure all fields are complete"
MsgBox msg
GoTo Finish
End If
 
i = 0
Do
i = i + 1
Loop Until priv.Cells(i + 2, 1) = ""
 
If optopen = True Then word = OPEN      'NEED HELP HERE... These are option buttons
If optclose = True Then word = CLOSE     'NEED HELP HERE... These are option buttons
 
priv.Cells(i + 2, 1) = txtdate
priv.Cells(i + 2, 2) = "=WORKDAY(A" & (i + 2) & ",3,PARAMETERS!$D$3:$D$65536)"
priv.Cells(i + 2, 3) = word
 
Unload Me
 
Finish:
End Sub
 
 
Private Sub UserForm_Initialize()
Set portugal = Worksheets("PORTUGAL")
Set priv= Worksheets("PRIVATE")
Set param= Worksheets("PARAMETERS")
 
datetoday = Format(DateTime.Now, "mm/dd/yyyy")
txttradedate = datetoday
 
End Sub
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
the words have to be pasted into cells after the insert button is pressed... something to followup. I need this text because of the following line:

Code:
priv.Cells(i + 2, 11) = "=IF(C" & (i + 2) & "=[COLOR=red][B]OPEN[/B][/COLOR],SUM(I" & (i + 2) & ":J" & (i + 2) & "),I" & (i + 2) & "-J" & (i + 2) & ")"

The following code should be when inserted into a cells after pressing the Insert button. The above has to be exactly as the below:
Code:
=IF(C2="OPEN",SUM(I2:J2),I2-J2)
 
Upvote 0
Hi,

You will need to add the quotations into the VBA also, not sure on the syntax so try these, one should work;

Code:
priv.Cells(i + 2, 11) = "=IF(C" & (i + 2) & "="OPEN",SUM(I" & (

Or

Code:
priv.Cells(i + 2, 11) = "=IF(C" & (i + 2) & "=""OPEN"",SUM(I" & (
 
Upvote 0

Forum statistics

Threads
1,203,069
Messages
6,053,352
Members
444,655
Latest member
didr

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