Results 1 to 6 of 6

Thread: [RESOLVED] For IF Loop

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2009
    Posts
    448

    Resolved [RESOLVED] For IF Loop

    How do I get this to look at the RC[4] and not insert the Hyperlink if there is nothing there?
    Code:
            For i = 6 To 82
            
            With Cells(i, 1)
            .FormulaR1C1 = "=HYPERLINK(""http://eic.mycom.com/eic_drw/qr/"" &RC[4],RC[4])"
            With .Font
            .Bold = True
            .Name = "Arial"
            .Size = 12
            .Underline = xlUnderlineStyleSingle
            .ColorIndex = 5
           
            End With
            End With
            Next

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: For IF Loop

    what is rc[4]?
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  3. #3
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: For IF Loop

    And, what is the purpose of the 2nd With/End With?

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2009
    Posts
    448

    Re: For IF Loop

    RC[4] is the offset. It ends up being the End of the Link, and the Hyperlink Friendly Name in the Formula. Which is like 054049-001.
    The Two End With's is I assume needed to be there because there are Two with's. Ohh so your saying I can take away the 2nd With. I think that is a problem with Recording Macros and it being all about Selection this and Selection that. If I could only make it Record in Range Format I think it would be better. Since it is my understanding that you should always convert to Range Format and not Select Cells/Ranges in order to do Stuff.

  5. #5
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: For IF Loop

    Try this

    Code:
    For i = 6 To 82
        With Cells(i, 1)
            '~~> Check if offset is not empty
            If Len(Trim(.Offset(0, 4).Value)) <> 0 Then
                .FormulaR1C1 = "=HYPERLINK(""http://eic.mycom.com/eic_drw/qr/"" & RC[4],RC[4])"
                With .Font
                    .Bold = True
                    .Name = "Arial"
                    .Size = 12
                    .Underline = xlUnderlineStyleSingle
                    .ColorIndex = 5
                End With
            Else
                '~~> Your code here if the offset cell is empty
            End If
        End With
    Next
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2009
    Posts
    448

    Re: For IF Loop

    Thanks Sid. Got it working.

Posting Permissions

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



Click Here to Expand Forum to Full Width