Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / January 2008

Tip: Looking for answers? Try searching our database.

Alpha/Numeric help

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Rick S. - 23 Jan 2008 01:28 GMT
[looks at box]
I'm stuck.
[/Looks at box]

I have a worksheet where the cell range has gone into double alpha
characters (IE "AA6") and I can't seem to find a way to work with it in my
code.

I retrieve a cell address and manipulate it to create ranges, once my cells
get into double alpha characters it will fail.  For an example, one work
sheet has cells from "A5" through "AA23", with  my code I end up with a range
of "C5 through "A23" instead of "C5" through "AA23".  I understand why, but I
don't see how to fix it.

Thanks in advance.

'======
       'Begin FindCellRange=====================================
       Dim x As Long, SRng As Range, Rcount As Long
       Dim sRange
       Dim sRow As String
       Dim sRow2 As String

       Set SRng = ActiveSheet.UsedRange
       Rcount = SRng.Rows.Count
       For x = Rcount + SRng.Row To 1 Step -1
           If Application.CountA(SRng.Rows(x)) <> 0 Then Exit For
       Next x
       'MsgBox "First empty row is " & SRng.Rows(x + 1).Address(0, 0) 'for
testing value
       sRow = Right(SRng.Rows(x + 1).Address(0, 0), 3)
       sRow = Replace(sRow, ":", "")
       If Len(sRow) = "2" Then
           sRow2 = Left(sRow, 1)
           'MsgBox "Len(sRow2) = ""2"" " & sRow2 'for testing
       Else
           If Len(sRow) = "3" Then 'double alpha characters fail, IE:
address "AA6". 01.20.08
               sRow2 = Left(sRow, 2)
               sRow2 = Left(sRow2, 1)
               'MsgBox "Len(sRow2) = ""3"" " & sRow2 'for testing
           End If
       End If
       'End FindCellRange=======================================

'======
Signature

Regards

VBA.Noob.Confused
XP Pro
Office 2007

Dave Peterson - 23 Jan 2008 02:16 GMT
Don't build a string of addresses.  It's too much work.  But I'm confused at
what you're doing.  I'm not sure if you included test code in your post.  

But this may help (or not!)...

When I want to loop through a range and determine a subset of that range:

Dim myRng as range
dim myCell as range
dim myRngOk as range

set myrng = somerangehere
set myrngok = nothing
for each mycell in myrng.cells
  if mycell.value = something then
      'add it to the ok rng
      if myrngok is nothing then
         set myrngok = mycell
      else
         set myrngok = union(myrngok,mycell)
      end if
  end if
next mycell

then I can use:

if myrngok is nothing then
  msgbox "no cells found"
else
  msgbox myrngok.address
  'or
  msgbox myrngok.entirerow.address
end if

> [looks at box]
> I'm stuck.
[quoted text clipped - 48 lines]
> XP Pro
> Office 2007

Signature

Dave Peterson

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.