Set each cell in a range to a specifc Text Value

blbat

Active Member
Joined
Mar 24, 2010
Messages
338
Office Version
  1. 2016
  2. 2013
I want to set every cell in a Range to specific Text value- I haven't got it yet, but this is the approach I've started with... it doesn't work. What's the correct method?


Code:
Private Sub cmdResetVisCheck_Click()

Dim mySheetWS as Worksheet, VisRng as Range
 
Set mySheetWS = Worksheets("Parts Wrkup")
Set VisRng = mySheetWS.Range("V2:V" & mySheetWS.Cells(Rows.Count, "V").End(xlup).Row

'Next is set each cell value in Range to "Visual Check"
'******************************************
For Each Cell in Range(VisRng)
   
Cell.Value = "Visual Check"

Next

End Sub

Thanks.
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
How about
Code:
Private Sub cmdResetVisCheck_Click()

Dim mySheetWS As Worksheet, VisRng As Range
 
Set mySheetWS = Worksheets("Parts Wrkup")
Set VisRng = mySheetWS.Range("V2:V" & mySheetWS.Cells(Rows.Count, "V").End(xlUp).Row[COLOR=#ff0000])[/COLOR]

'Next is set each cell value in Range to "Visual Check"
'******************************************
For Each cell In [COLOR=#ff0000]VisRng[/COLOR]
   
cell.Value = "Visual Check"

Next

End Sub
2 corrections in red.
But if col V is empty this still won't work. let us know what happens
 
Upvote 0
I am pretty sure this one-liner will do what you are attempting to do with the code you posted...
Code:
[table="width: 500"]
[tr]
	[td]Private Sub cmdResetVisCheck_Click()
  Worksheets("Parts Wrkup").Range("V2", Worksheets("Parts Wrkup").Cells(Rows.Count, "V").End(xlUp)) = "Visual Check"
End Sub[/td]
[/tr]
[/table]
 
Upvote 0
Thank you Both-

Both examples worked.


Fluff- Thx, your code showed me that at least I was on a correct trajectory to accomplishing my goal!

Rick- Thank you for showing me, AGAIN, that I need to think about a simpler way to do what I'm doing in my code.

regards,

blbat
 
Last edited:
Upvote 0
Glad we could help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,767
Messages
6,174,395
Members
452,561
Latest member
amir5104

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