Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Posting on Qlik Community is temporarily paused for some users. Thank you for patience and we'll update you soon!
cancel
Showing results for 
Search instead for 
Did you mean: 
sunny_talwar
MVP
MVP

Macro for Border (Part 3)

Now in the third part (after Macro for Border and Macro for Border (Part 2)) I need to apply formating to more than one row. For example

Header 1Header 2Header 3
XYZ1020
ABC3040
Total14060
PQR3040
Total21020

Now my goal is to add the border for Header 2 and Header 3 which corresponds to the cell which says Total1 and Total2

I guess I can write a long code which will work, but is there a for loop I can use here to avoid writing a huge code?

tamilarasu‌, marcus_sommer‌

Thanks,

Sunny

Update: Highlighted the text in red to show which cells need to be formatted

Labels (1)
1 Solution

Accepted Solutions
sunny_talwar
MVP
MVP
Author

I think I got this one as well using a second loop

WhatToFind = Array("Total1", "Total2")

    For iCtr = LBound(WhatToFind) To UBound(WhatToFind)

   

         For vOffset = 2 to 3

  

              Set Rng = XLSheet.Cells.Find(WhatToFind(iCtr)).Offset(0, vOffset)

View solution in original post

3 Replies
sunny_talwar
MVP
MVP
Author

So I have handled this partially for each of the search word, now I need to get this for two columns

WhatToFind = Array("Total1", "Total2")

   

    For iCtr = LBound(WhatToFind) To UBound(WhatToFind)

  

    Set Rng = XLSheet.Cells.Find(WhatToFind(iCtr)).Offset(0, 2)

sunny_talwar
MVP
MVP
Author

I think I got this one as well using a second loop

WhatToFind = Array("Total1", "Total2")

    For iCtr = LBound(WhatToFind) To UBound(WhatToFind)

   

         For vOffset = 2 to 3

  

              Set Rng = XLSheet.Cells.Find(WhatToFind(iCtr)).Offset(0, vOffset)

tamilarasu
Champion
Champion

Hi Sunny,

Again sorry for the delayed reponse. Here is the code.

Set objCells=XLSheet.Cells 
With objCells 
  Set c = .Find ("Total*") 
  If Not c Is Nothing Then 
  firstAddress = c.Address 
  Do
   Set Rng = XLSheet.Range("B" & c.row & ":C" & c.row)
   With Rng.Borders(8)
     .LineStyle = 1
     .Weight = 2
     .ColorIndex = 0
     .TintAndShade = 0
    End With

   With Rng.Borders(9)
    .LineStyle = -4119
    .ColorIndex = 0
    .TintAndShade = 0
    .Weight = 4
   End With
Set c = .FindNext(c) 
Loop While Not c Is Nothing And c.Address <> firstAddress 
End If
End With