DeeWBee
DeeWBee

Reputation: 695

VBA Changing Value of Multiple Cells

I have a row of cells that depending on which option button I have selected, will display a certain range of values. It isn't based on any equations or any logic. I need to display a specific set of values across multiple cells.

Private Sub OptionButton1_Click()
If OptionButton1.Value = True Then Range("B3","AF3").Value = 

End Sub

How would I indicate multiple values across cells in this case? Would I put all my values into some sort of an array first and then just feed the array into the .Value? Thanks!

Upvotes: 1

Views: 12890

Answers (2)

DeeWBee
DeeWBee

Reputation: 695

The method I ended up using is as follows.

Worksheets("Sheet1").Range("B3","AF3").Value = Worksheets("Sheet2").Range("B3","AF3").Value

Upvotes: 3

sous2817
sous2817

Reputation: 3960

There is probably a more elegant way, but here is one way to go about it:

Sub test()

Dim strArray(0 To 2)    As String
Dim rng                 As Range
Dim cell                As Range
Dim counter             As Long

Set rng = Range("A3,B7,G5")
counter = 0

strArray(0) = "Value1"
strArray(1) = "Value2"
strArray(2) = "Value3"

For Each cell In rng
    cell.Value = strArray(counter)
    counter = counter + 1
Next cell

End Sub

Upvotes: 2

Related Questions