Consulting

Results 1 to 11 of 11

Thread: Solved: Numpty question, but I'm not too proud to ask for help...

  1. #1
    VBAX Regular
    Joined
    Oct 2007
    Location
    Sheffield
    Posts
    63
    Location

    Solved: Numpty question, but I'm not too proud to ask for help...

    Hello
    I've created this code below. The aim of it is to create a unique identifier name based on the contents of 3 cells in the same row (by concatenating the contents), namely in columns B, C and E. The VB editor highlights the 'assignment' statement in red (syntax is wrong).

    So, for example, when i=2, cell A2 should equal 'B2&C2&E2'

    Can someone help me out, please?

    [vba]Public Sub CreateUniqueIdentifier()
    Dim i As Long
    Dim iLastRow As Long

    With ActiveSheet

    iLastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
    iStart = 1
    .Cells(1, "A").Value = "Identifier"
    For i = 2 To iLastRow
    .Cells(i, "A").Value = (B$i)&(C$i)&(E$i)
    Next i
    End With
    End Sub
    [/vba]
    Last edited by Lester; 11-02-2007 at 07:56 AM.

  2. #2
    VBAX Expert Dave's Avatar
    Joined
    Mar 2005
    Posts
    835
    Location
    HTH. Dave
    [VBA]
    For i = 2 To iLastRow
    .Cells(i, "A").Value = .Cells(i, "B").Value _
    & Cells(i, "C").Value & Cells(i, "E").Value
    Next i
    [/VBA]

  3. #3
    VBAX Regular
    Joined
    Oct 2007
    Location
    Sheffield
    Posts
    63
    Location
    Dave - cheers for the corrections, man.
    I am such a dunce. I had also defined iLastRow as:

    [vba]
    iLastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
    [/vba]

    ...but column A was empty, so iLastRow was zero!

    I've now changed it to B, thus:

    [vba]
    iLastRow = .Cells(.Rows.Count, "B").End(xlUp).Row
    [/vba]

    Gawd!

    Many thanks
    Lester

  4. #4
    Another "not great" title for a thread.
    Lester, you said you were going to try harder !
    2+2=9 ... (My Arithmetic Is Mental)

  5. #5
    VBAX Regular
    Joined
    Oct 2007
    Location
    Sheffield
    Posts
    63
    Location
    Quote Originally Posted by unmarkedhelicopter
    Another "not great" title for a thread...
    Indeed, unmarkedH - not at all succinct. I apologise. It somehow captured the overwhelming feeling of helplessness, at not having anyone to turn to at work to solve the problem.
    Cheers

  6. #6
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,060
    Location
    Numpty... Not a word generally heard these days. Any specific value attached?
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  7. #7
    VBAX Regular
    Joined
    Oct 2007
    Location
    Sheffield
    Posts
    63
    Location
    Quote Originally Posted by Aussiebear
    Numpty... Not a word generally heard these days. Any specific value attached?
    Hi Aussibear
    ...See definition 2 here! Sums me up w.r.t. VBA at the mo'.

    Cheers

  8. #8
    VBAX Master paulked's Avatar
    Joined
    Apr 2006
    Posts
    1,007
    Location
    I like that dictionary.
    Semper in excretia sumus; solum profundum variat.

  9. #9
    VBAX Master Norie's Avatar
    Joined
    Jan 2005
    Location
    Stirling, Scotland
    Posts
    1,831
    Location
    Lester

    Why loop?
    [vba]
    Public Sub CreateUniqueIdentifier()
    Dim iLastRow As Long

    With ActiveSheet

    iLastRow = .Range("B" & .Rows.Count).End(xlUp).Row

    .Cells(1, "A").Value = "Identifier"

    With .Range("A2:A" & iLastRow)
    .Formula = "=B2&C2&E2"
    .Value = .Value
    End With

    End With

    End Sub[/vba]

  10. #10
    VBAX Regular
    Joined
    Oct 2007
    Location
    Sheffield
    Posts
    63
    Location
    @Norie...Thank you v.much - I will give that a try and let you know how I get on. It looks like a more succinct solution.

    Cheers
    Lester

  11. #11
    VBAX Regular
    Joined
    Oct 2007
    Location
    Sheffield
    Posts
    63
    Location
    Many thanks, Norie.
    Your code worked a treat. You are very helpful.
    I suppose avoiding the loop speeds up the calculation.

    Cheers
    Lester

Posting Permissions

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