columns in refedit to a combobox

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

How can I populate a ComboBox with the columns of a range selected in a
RedEdit?

Thanks in advance
 
with userform1
.combobox1.text = .refedit1.text
end with

lets say the string return is
refeditrange = "sheet1!$A5:$B10"
You can extract the columns using string references or cell references

set cellrange = range(refeditrange)
firstcol = cellrange.column
lastcolumn = firstcol + cellrange.columns - 1

you can do the same using string manipulations

Sub test()

refeditrange = "sheet1!$A5:$B10"

'get everything after first $
Firstcol = Mid(refeditrange, _
InStr(refeditrange, "$") + 1)
Lastcol = Firstcol
'check if column is one letter of two letters
If IsNumeric(Mid(Firstcol, 2, 1)) Then
'Column is A - Z
Firstcol = Left(Firstcol, 1)
Else
'Column is AA - IV
Firstcol = Left(Firstcol, 2)
End If
'get characters after 2nd $
Lastcol = Mid(Lastcol, _
InStr(Lastcol, "$") + 1)
If IsNumeric(Mid(Lastcol, 2, 1)) Then
'Column is A - Z
Lastcol = Left(Lastcol, 1)
Else
'Column is AA - IV
Lastcol = Left(Lastcol, 2)
End If

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top