Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 26th, 2003, 12:45 PM
sniperonpatrol sniperonpatrol is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Location: Dublin, Ireland
Posts: 2 sniperonpatrol User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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.

Reply With Quote
  #2  
Old November 26th, 2003, 12:55 PM
Fisherman's Avatar
Fisherman Fisherman is offline
Inherits Programmer.Slacker
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Aug 2003
Location: Between my Id and your Ego
Posts: 2,178 Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 1 Week 1 Day 9 h 56 m 45 sec
Reputation Power: 111
Send a message via ICQ to Fisherman Send a message via AIM to Fisherman
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

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming > Selecting a range in Excel


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT