|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Selecting a range in Excel
I am trying (unsuccessfully) to take a value from a cell in Excel and use that value to determine how many cells in a column to select.
For Eg. If A1=10, I want to select Range("C10:C 10+10") I have tried CellNo = 10 cellchk = "$C$" & CStr(CellNo) Range(cellchk).Select Selection.AutoFill Destination:=Range("C10:"$E$" & CSTR ...... ............ (CellNo)"), Type:=xlFillDefault But this doesnt work. It works fine when selecting a 1 entry range cellchk = "$C$" & CStr(CellNo) Range(CellChk).Select but not when selecting a multi entry range. The program I am working on feeds its values into Excel to sort results, produce graphs etc. Hopefully someone has come across a similar problem and can help me out. Cheers. |
|
#2
|
||||
|
||||
|
hey sniper... I wrote a Function called ExcelCells which will return as string to function as a range in an Excel application call... see if you can modify it to make it work for you.
Code:
Public Function ExcelCells(intCallingForm As Integer)
Dim intI As String, intJ As Integer
Dim intConv As Integer, intConv2 As Integer
Dim strConv As String, strConv2 As String, strCell As String
If intCallingForm = 0 Then
intI = frmGraph.Pego1.Points + 1
If intI > 26 Then
intConv2 = intI Mod 26
If intConv2 = 0 Then
strConv2 = "A"
Else
strConv2 = Chr((intConv2 + 65))
End If
intConv = Fix(intI / 26)
strConv = Chr((intConv + 64))
strCell = strConv + strConv2
Else
strConv = Chr((intI + 65))
strCell = strConv
End If
Else
intI = frmAdGraph.Pego1.Points + 1
If intI > 26 Then
intConv2 = intI Mod 26
If intConv2 = 0 Then
strConv2 = "A"
Else
strConv2 = Chr((intConv2 + 65))
End If
intConv = Fix(intI / 26)
strConv = Chr((intConv + 64))
strCell = strConv + strConv2
Else
strConv = Chr((intI + 65))
strCell = strConv
End If
End If
ExcelCells = strCell
End Function
Note: pay no attention to the (intcallingform) argument or the conditional based on it - it was something specific to the program I was working with at the time.
__________________
Fisherman "Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius -- and a lot of courage -- to move in the opposite direction." - A.Einstein |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > Visual Basic Programming > Selecting a range in Excel |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|