Change Reference to Columns in a Macro
Hi,
I have read your question many times and still I am not sure if I am
correctly interpreting what it is that you want. I am assuming that you want
to reference Cells and Ranges using variables instead of hard coding the
actual Cell/Range address. Have a look at the following examples of
referencing cells and ranges in VBA code and see if it answers your question.
Note: When using Cells function to reference cells, the row is first
followed by the column. That is Cells(RowNumber,ColNumber). This is back to
front to the way they are referenced with Range(ColId : RowNumb)
Dim lngRowNumber As Long
Dim lngColNumber As Long
Dim strCol1 As String
Dim strCol2 As String
lngRowNumber = 4
lngColNumber = 5
'Following same as Range("E5").Select
Cells(lngRowNumber, lngColNumber).Select
'Following same as Range("E4:G6").Select
Range(Cells(lngRowNumber, lngColNumber), Cells(6, 7)).Select
strCol1 = "F"
'Following same as Range("F:G").Select
Range(strCol1 & ":G").Select
strCol2 = "H"
'Following same as Range("F:H").select
Range(strCol1 & ":" & strCol2).Select
--
Regards,
OssieMac
"Nastech" wrote:
hi, is there a way to modify the reference to columns,
to be from a different single cell, such as INDIRECT..
within a macro / script? Thanks
the type of lines I want to reference a
Range("A1").Value
Columns("B:C").Select
Range("D:E").Select
Intersect(Me.Range("F:G"),
With Me.Cells(.Row, "H")
|