Option Explicit
Sub HTMacro()
Dim KeyRow As Range
Dim KeyRange As Range
Dim Advert As Long, Admin As Long, Maint As Long, PayRoll As Long, Mgmt As Long
Dim Utl As Long, TaxIns As Long, Repairs As Long, Improve As Long, rev As Long
Dim ParentWB As String
Dim NewFN As Variant
Dim wbNew As Workbook
Dim nProperties As Integer, nExpItem As Integer, iRow As Integer, iCol As Integer
Dim MakeRdy As Variant
Dim contSvc1 As Variant
Dim contSvc2 As Variant
Dim iNS As Variant
Dim tAX As Variant
Dim Improvements As Variant
Dim nMonths As Variant
Dim NOI As Variant
Application.ScreenUpdating = False
ParentWB = ActiveWorkbook.Name
NewFN = Application.GetOpenFilename(Title:="Please select a file")
If NewFN = False Then
' They pressed Cancel
MsgBox "Stopping because you did not select a file"
Exit Sub
Else
Set wbNew = Workbooks.Open(Filename:=NewFN)
End If
With wbNew.Sheets("12 mo inc det")
.Unprotect
.Columns("A:B").EntireColumn.Hidden = False
.Range("ah12").Value = "1"
.Range("ah12").Copy
.Columns("a:a").PasteSpecial Paste:=xlPasteAll, Operation:=xlMultiply
'Find function does not find requested data************************************************************************
'Note no period before columns and cells
Set KeyRow = Columns(1).Find(what:="5199", LookIn:=xlValues, lookat:=xlPart)
If KeyRow Is Nothing Then
MsgBox "not found"
Else
Advert = (.Cells(KeyRow.Row, 14).Value)
End If
' period in front of columns and cells
Set KeyRow = .Columns(1).Find(what:="5299", LookIn:=xlValues, lookat:=xlPart)
If KeyRow Is Nothing Then
MsgBox "not found"
Else
Admin = (.Cells(KeyRow.Row, 14).Value)
End If
Set KeyRow = .Columns(1).Find(what:="5699", LookIn:=xlValues, lookat:=xlPart)
If KeyRow Is Nothing Then
MsgBox "not found"
Else
Maint = (.Cells(KeyRow.Row, 14).Value)
End If
Set KeyRow = .Columns(1).Find(what:="5799", LookIn:=xlValues, lookat:=xlPart)
If KeyRow Is Nothing Then
MsgBox "not found"
Else
PayRoll = (.Cells(KeyRow.Row, 14).Value)
End If
Set KeyRow = .Columns(1).Find(what:="5899", LookIn:=xlValues, lookat:=xlPart)
If KeyRow Is Nothing Then
MsgBox "not found"
Else
Mgmt = (.Cells(KeyRow.Row, 14).Value)
End If
Set KeyRow = .Columns(1).Find(what:="5999", LookIn:=xlValues, lookat:=xlPart)
If KeyRow Is Nothing Then
MsgBox "not found"
Else
Utl = (.Cells(KeyRow.Row, 14).Value)
End If
Set KeyRow = .Columns(1).Find(what:="7999", LookIn:=xlValues, lookat:=xlPart)
If KeyRow Is Nothing Then
MsgBox "not found"
Else
Repairs = (.Cells(KeyRow.Row, 14).Value)
End If
Set KeyRow = .Columns(1).Find(what:="8995", LookIn:=xlValues, lookat:=xlPart)
If KeyRow Is Nothing Then
MsgBox "not found"
Else
Improve = (.Cells(KeyRow.Row, 14).Value)
End If
Set KeyRow = .Columns(1).Find(what:="8999", LookIn:=xlValues, lookat:=xlPart)
If KeyRow Is Nothing Then
MsgBox "not found"
Else
rev = (.Cells(KeyRow.Row, 14).Value)
End If
End With
Windows(ParentWB).Activate
'Advert = 55555
'Admin = 8888
With Range("A3")
'nExpItem = Range(.Offset(3, 3), .Offset(3, 3).End(xlToRight)).Columns.Count
'nProperties = Range(.Offset(4, 1), .Offset(4, 1).End(xlDown)).Columns.Select
iRow = Range(.Offset(2, 3), .Offset(2, 3).End(xlDown)).Rows.Count
End With
With DataInput.Range("D5")
.Cells(iRow + 1, 1).Value = Advert
.Cells(iRow + 1, 2).Value = Admin
' .Cells(iRow + 1, 3).Value = "=" & Maint & "-" & MakeRdy & "-" & contSvc1 & "-" & contSvc2
.Cells(iRow + 1, 4).Value = MakeRdy
' .Cells(iRow + 1, 5).Value = "=" & contSvc1 & "+" & contSvc2
.Cells(iRow + 1, 6).Value = PayRoll
.Cells(iRow + 1, 7).Value = Mgmt
.Cells(iRow + 1, 8).Value = Utl
.Cells(iRow + 1, 9).Value = iNS
' .Cells(iRow + 1, 10).Value = "=" & tAX & "-" & iNS
.Cells(iRow + 1, 11).Value = Repairs
.Cells(iRow + 1, 12).Value = Improvements
.Cells(iRow + 1, 14).Value = rev
' Check Cells
If Abs(.Cells(21, nMonths + 2) - NOI) > 2 Then MsgBox "Check Error"
End With
'more action here
wbNew.Close savechanges:=False 'close with changes
Set wbNew = Nothing
End Sub
Bookmarks