I am trying to get how to reference a cell in an excel table from Columns(1) I see how Cells.offset(0,1) will do Columns(2) / or (0,2) Columns(3). That works, but I don't need it to go through all the workbook sheets then insert the last IPa into all the sheets. It takes a lot longer to run and not what I am looking for. Any pointer on what changes need to be done?
Code:
Option Explicit
Sub AddSheets()
Dim IPA As String
Dim WkBk As Workbook, WkSht As Worksheet
Dim RCnt As Long, RwCnt As Long, IPCnt As Long, TblCnt As Long
Dim Cell As Range, Table1 As ListObject
Set WkBk = Nothing
Set WkSht = Nothing
Set WkBk = ActiveWorkbook
Set WkSht = ActiveSheet
ActiveWorkbook.Sheets("Baseline").Activate
Call ClearTable
Application.ScreenUpdating = False
Set Table1 = Worksheets("Baseline").ListObjects.Add(1, Range("A4:C100"), , xlYes)
TblCnt = Table1.ListRows.Count 'trying to use the row count to ensure we are looking at the right cell. TblCnt shows the MAX number of rows. ?? RwCnt = 1 to TblCnt next RwCnt ???
For Each Cell In Table1.DataBodyRange.Columns(1).Cells
If SheetExists(Cell.Value) = False And Cell.Value <> "" Then
Set WkSht = Sheets.Add(before:=Sheets(Sheets.Count))
WkSht.Name = Cell.Value
End If
For Each WkSht In Worksheets
Select Case WkSht.Name
Case "Baseline"
Case "System Count"
Case Else
With WkSht
.Range("A1:A3").Font.Bold = True
.Range("A1:A3").Font.ColorIndex = 1
.Range("A1:A3").Font.Size = 11
.Range("A1:A3").Interior.ColorIndex = 15
.Cells(1, 1) = "Network IP"
.Cells(1, 2) = Cell.Offset(0, 1) & "0.0"
.Cells(2, 1) = "SubNet"
.Cells(3, 1) = "Broadcast IP"
ActiveSheet.Cells(1, 3).Select
.Cells(1, 3).Hyperlinks.Add Anchor:=Selection, Address:="", SubAddress:="'System Count'!A1", TextToDisplay:="System Count"
ActiveSheet.Cells(5, 1).Select
.Range("A5:F5").Font.Bold = True
.Range("A5:F5").Font.ColorIndex = 1
.Range("A5:F5").Font.Size = 11
.Range("A5:F5").Interior.ColorIndex = 15
.Cells(5, 5) = "System Owner"
.Cells(5, 1) = "IP Address"
.Cells(5, 2) = "URN"
.Cells(5, 3) = "Role Name"
.Cells(5, 4) = "System Type"
.Cells(5, 6) = "Notes"
ActiveSheet.Range("A1:F1").Select
ActiveSheet.Range("A1:F1").EntireColumn.AutoFit
If Cell.Offset(0, 1) = "" Then
IPA = "0.0.0.0"
Else
For IPCnt = 1 To 10
IPA = Cell.Offset(0, 1) & Cell.Offset(0, 2) & "." & IPCnt
.Cells(IPCnt + 5, 1) = IPA
Next IPCnt
End If
End With
End Select
Next WkSht
Next Cell
Call ClearTable
Set WkSht = Nothing
Set WkBk = Nothing
Application.ScreenUpdating = True
End Sub