sspatriots
Well-known Member
- Joined
- Nov 22, 2011
- Messages
- 585
- Office Version
- 365
- Platform
- Windows
This is the same code I was working with earlier that I had posted a different issue with that seems to be working fine now. However, when I get to the lines below, I would like to try and get these to where all that is needed is have the hyperlinks in "rng4" show up on the same column in another table called "rng5". My first try was to copy the formats from "rng5" to "rng4" first and then copy everything back to "rng5" so that I didn't lose the original cell formatting of "rng5". I would like to do this without having to use copy and past and somehow set ranges equal to one another, because I understand that selecting ranges to copy and paste from one range to another slows the code down. Any suggestions would me greatly appreciated. Thanks, SS
VBA Code:
rng5.Copy
rng4.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
rng4.Copy
rng5.PasteSpecial.Hyperlinks (1)
VBA Code:
Sub CreateHyperlinks2024()
Dim wb1 As Workbook
Dim ws1 As Worksheet, ws2 As Worksheet
Dim tb1 As ListObject, tb2 As ListObject
Dim rng1 As Range, rng2 As Range, rng3 As Range, rng4 As Range, rng5 As Range
Dim cl As Range
Dim numRows As Long
Set wb1 = ThisWorkbook
Set ws1 = wb1.Worksheets("2024")
Set ws2 = wb1.Worksheets("PO File Paths")
Set tb1 = ws1.ListObjects("Table4711")
Set tb2 = ws2.ListObjects("POHLINKCNV")
Set rng1 = Range("Table4711[#All]")
Set rng2 = Range("POHLINKCNV[#All]")
Set rng3 = Range("POHLINKCNV[Full PO '#]")
Set rng4 = Range("POHLINKCNV[Hyperlink]")
Set rng5 = Range("Table4711[PO'#]")
' rng5.Select
With Application
.EnableEvents = False
.ScreenUpdating = False
' .CutCopyMode = False
' .DisplayAlerts = False
.Calculation = xlCalculationManual
End With
Sheets("PO File Paths").Select
' POFilePaths2024
With Range("FilePathRange")
.ClearFormats
.ClearHyperlinks
End With
numRows = rng1.SpecialCells(xlCellTypeLastCell).Row - 1
Set rng2 = rng2.Resize(numRows)
tb2.Resize rng2
With rng3
.ClearContents
.Formula2R1C1 = _
"=IFERROR(IF(OFFSET(Table4711[@[PO'#]],1,0)=""""," & Chr(10) & """""," & Chr(10) & "OFFSET(Table4711[@[COMPL PO NO CORR]],1,0))," & Chr(10) & "OFFSET(Table4711[[#Headers],[COMPL PO NO CORR]],1,0))"
End With
rng4.ClearContents
With rng4
.ClearContents
.FormulaR1C1 = "=IFERROR(VLOOKUP(""*""&IF(POHLINKCNV[@[Full PO '#]]="""","""",POHLINKCNV[@[Full PO '#]])&""*"",POFilePaths2024[PO File Paths - 2024],1,FALSE),"""")"
End With
With Range("FilePathRange")
.Value = .Value
End With
For Each cl In rng4.Cells '## Modify as needed
If cl <> "" Then
cl.Hyperlinks.Add cl, cl.Value, , , cl.Offset(0, -1).Value
cl = Right(cl, Len(cl) - 5)
End If
On Error Resume Next
If cl = "" Then
cl = cl.Offset(0, -1).Value
cl = Right(cl, Len(cl) - 5)
End If
Next
rng5.Copy
rng4.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
rng4.Copy
rng5.PasteSpecial.Hyperlinks (1)
IdentifyCellsWithHyperlink
With Application
.EnableEvents = True
' .ScreenUpdating = True
.CutCopyMode = False
' .DisplayAlerts = False
.Calculation = xlAutomatic
End With
End Sub