Inserting value from macro into worksheet cell

dpbarry

Board Regular
Joined
Feb 10, 2003
Messages
214
Office Version
  1. 2016
Platform
  1. Windows
Hi Folks..

Having a brain dead day..

I have the following macro that changes the contents of a cell to a given text

Sub months()
Dim wks As Worksheet
Dim str As String
str = InputBox("Enter Month")
For Each wks In Worksheets(Array("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21"))
wks.Range("O4") = str
Next wks
End Sub

I have had to add in another worksheet to the Spreadsheet called 'CG48X' and would like to put the str value into the cell R4.

Obviously I'd have to put it outside the loop after the 'Next wks' but I can't work out the syntax.

Can anone help?

Regards

Declan
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Maybe try:

Code:
Sub months()
Dim wks As Worksheet
Dim str As String
str = InputBox("Enter Month")
For Each wks In Worksheets(Array("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21"))
wks.Range("O4") = str
Next wks
Sheets("CG48X").range("R4").value = str
End Sub
Hope that helps.
 
Upvote 0

Forum statistics

Threads
1,203,605
Messages
6,056,251
Members
444,853
Latest member
sam69

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