-1

I have an array of integers (dfArray) and would like to create a new second String array which consists of the integers and appending "G" to the beginning. What's the best way to go about this? I was thinking of For Each but couldn't get it to work. Thanks in advance.

Set dfArray = [dff]
Set dfArray2 = ["G" & dff]  'incorrect but you get the idea?
sybb
  • 169
  • 1
  • 7
  • what is [dff] ? – Dy.Lee Jan 14 '18 at 00:50
  • You don't **set** arrays; you **assign** them. –  Jan 14 '18 at 01:11
  • [dff] is a Range containing text numbers: 0001, 0002, 0007 etc. I am able to convert each Range to an Integer but unable to access it outside the scope. I think I've learnt that this can't be done using For loops. I'll take a step back so you can understand what I'm trying to do: `Application.WorksheetFunction.Max(dfArray2)` I want to find the maximum value within this Range however; the Range values are stored as text in the workbook (this must be stored as text). – sybb Jan 14 '18 at 01:20

1 Answers1

1
Dim dfArray() As Variant
Dim dfArray2() As String

dfArray = [dff].Value

ReDim dfArray2(UBound(dfArray)) As String

Dim i As Double

For i = 1 To UBound(dfArray) Step 1
    dfArray2(i) = "G" & dfArray(i, 1)
Next i

Anyways, from my personal point of view, I don't like to asign a complete Range into Array, only if needed. I prefer to loop using Lbound or Ubound and control the array all the time. To asign a range into an Array, you need the Array variable to be Variant type, and also, you can't use Preserve easily. Check this question for more info

Issues about Variant Arrays

  • Your response solved my problem and has got me to better understand vba arrays. Cheers!! – sybb Jan 14 '18 at 03:06