Consulting

Results 1 to 8 of 8

Thread: Alternative To ActiveCell.Row

  1. #1

    Alternative To ActiveCell.Row

    Hello,

    Is there an alternative to ActiveCell.Row, in some cases I might need the data from more than just one cell...So if I use
    ActiveCell.Row, 2

    Well that is useful if I just want that cell...But what if I need to select several cells...and not just one...?

    Any alternative...?
    My Code now:
    [VBA]" Persons Name:" & wks.Cells(ActiveCell.Row, 17) & vbNewLine & vbNewLine & _[/VBA]

  2. #2
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    Type the word Range in the VBE and press F1. Range has several forms. One is to set the first cell, a comma, and then the seconnd cell would be like A1:B10. e.g.
    [VBA]Dim r as Range
    Set r=Range("A1:B10")
    'or
    Set r=Range("A1", "B10")[/VBA]

  3. #3
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    How would the data from more than one row manifest? If concatenating, just use

    [vba]

    With wks.Cells(ActiveCell.Row, 17)

    " Persons Name:" & .Value & " " & .Offset(1,0)Value & vbNewLine & vbNewLine & _

    ...
    End With
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  4. #4

    RE:

    Hello,

    Thanks for the responses...

    This here:
    [VBA]With wks.Cells(ActiveCell.Row, 17)
    " Persons Name:" & .Value & " " & .Offset(1,0)Value & vbNewLine & vbNewLine & _
    ...
    End With [/VBA]

    I had to alter to fit into my code to this:
    [VBA]"Persons Name:" & wks.Cells(ActiveCell.Row, 17) & .Value & " " & .Offset(1,0)Value & vbNewLine & vbNewLine & _[/VBA]

    But, VBE, just returns a 'Syntax Error', doesn't tell me where or what...
    Any suggestions?

  5. #5

    Re:

    Quote Originally Posted by Kenneth Hobs
    Type the word Range in the VBE and press F1. Range has several forms. One is to set the first cell, a comma, and then the seconnd cell would be like A1:B10. e.g.
    [vba]Dim r as Range
    Set r=Range("A1:B10")
    'or
    Set r=Range("A1", "B10")[/vba]

    I tried this method, but when I specify the range - VBE says, "Expected: Seperator, ) or semi-colon."

    And it wont accept that..If you have another suggestion though, please let me know!

  6. #6
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    If you can't do that then you have serious problems. Test it on a new instance of Excel in a new workbook.

    In the Immediate window, you can see the returned addresses.
    [VBA]Sub test()
    Dim r As Range
    Set r = Range("A1:B10")
    Debug.Print r.Address
    'or
    Set r = Range("B5", "W51")
    Debug.Print r.Address
    End Sub[/VBA]

  7. #7

    RE:

    Ok,

    That worked when I tried it in a new instance of Excel, but it didn't work in the script Im working on...In column C a user can select what options they want, by double-clicking in the cell (a check mark will apear)

    My biggest problem is, I cannot get the information the user selects to transfer from the excel sheet, to the word document...I attached an example using your method Kenneth...

    If you look at sheet1 in the VBE...I have all the necessary coding there for the check marks, it should just be a matter of altering module1

    Let me know your thoughts on how I can improve this!

    Thanks

  8. #8
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    Not sure what part of that has to do with what you asked here.

    There are other ways to do your task. I prefer to create the basic DOC files as DOT files and then I use FormFields, Bookmarks or delimited marked text and do a find/replace.

    Even a one record MailMerge is easily done. Record it in MSWord if you want to try that method. The tricky part is to set a new data source and sql.

    For one thing, you have a syntax error for one long string. Rather than making one big string, use the string concatenation method as you did for other parts. Or, use a method like this. You can use just one vbCrLf if you don't want blank lines between the text lines.
    [VBA] Dim s() As String, sString As String
    ReDim s(1 To 500) As String
    s(1) = "Hello World!"
    s(2) = "How are things going?"
    s(3) = "I hope that all is well."
    ReDim Preserve s(1 To 3) As String
    sString = Join(s, vbCrLf & vbCrLf)
    wdRng = sString[/VBA]


    At the end, add:
    [VBA] Set wdApp = Nothing[/VBA]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •