Hi,
I have spreadsheet which contains a column of client numbers. these are hyperlinks to worksheets on another workbook which has pivot tables with the names of these clients each on its own worksheet. I'm trying to write a macro which will count the number of clients in the list and update the number in the client column (the hyperlink display name). I can't seem to use the worksheet reference in the hyperlink to activate the correct worksheet. It just opens the workbook. Is there a way to do this?
So far I have:
Sub updateClientNumbers()
Dim countClients As Integer
Dim sheetname As String
Dim lnkH As Hyperlink
Dim wkb As Workbook
Dim pt As PivotTable
Dim sht As Worksheet
For Each lnkH In ActiveSheet.Hyperlinks
Set wkb = Workbooks.Open(lnkH.Address)
Set pt = ActiveSheet.PivotTables(1)
countClients = pt.RowRange.Cells.count - 2
lnkH.TextToDisplay = countClients
wkb.Close
Next
End Sub
Apologies for my very basic VBA, I may be trying to do it completely the wrong way. Any help would be greatly appreciated.
I have spreadsheet which contains a column of client numbers. these are hyperlinks to worksheets on another workbook which has pivot tables with the names of these clients each on its own worksheet. I'm trying to write a macro which will count the number of clients in the list and update the number in the client column (the hyperlink display name). I can't seem to use the worksheet reference in the hyperlink to activate the correct worksheet. It just opens the workbook. Is there a way to do this?
So far I have:
Sub updateClientNumbers()
Dim countClients As Integer
Dim sheetname As String
Dim lnkH As Hyperlink
Dim wkb As Workbook
Dim pt As PivotTable
Dim sht As Worksheet
For Each lnkH In ActiveSheet.Hyperlinks
Set wkb = Workbooks.Open(lnkH.Address)
Set pt = ActiveSheet.PivotTables(1)
countClients = pt.RowRange.Cells.count - 2
lnkH.TextToDisplay = countClients
wkb.Close
Next
End Sub
Apologies for my very basic VBA, I may be trying to do it completely the wrong way. Any help would be greatly appreciated.