Set a Range to a variable
On Tuesday, February 12, 2013 5:32:21 PM UTC-8, Howard wrote:
I am trying to set a group of four cell to three variables.
Dim sec1 As String (tried Value, Range and Variant also)
Dim sec2 As String
Dim sec3 As String
sec1 = Range("B3:E3").String (tried Value, Range and Variant also)
sec2 = Range("G3:J3").String
sec3 = Range("L3:O3").String
MsgBox sec1 & sec2 & sec3
The above produces every type miss match error available in Excel in the process.
When successful with that I then want to Randamize them something like
=Rand(sec1&" "&sec2&" "&sec3) back into three sets of four cells else where on the sheet.
Thanks,
Howard
This code by Witek works just great to take the 'verbage' from the three 4-cell arrays and display it in a Msgbox.
I thought I could do the next task once I got this far but I am falling short.
I want to take the arrays that are displayed perfectly in the msgbox and have the ability to put them into cells of my choice on the sheet, lets just say in
B10:E10, G10:J10, L10:O10.
So with code/loop put them in the the cells just mentioned and follow in each row below the next with the scheme as listed here. Where I would end up with all six possible combinations in consecutive rows.
I would appreciate your help.
Howard
123
132
213
231
312
321
Option Explicit
Sub ThreeSecs()
'BY: Witek
Dim sec1 As Variant
Dim sec2 As Variant
Dim sec3 As Variant
Dim msg As String
Dim s As Variant
sec1 = Range("B3:E3").Value
sec2 = Range("G3:J3").Value
sec3 = Range("L3:O3").Value
For Each s In sec1 ' 2 and 3
msg = msg + s
Next s
MsgBox msg
End Sub
|