sts8500man
Board Regular
- Joined
- Jul 12, 2012
- Messages
- 77
- Office Version
- 365
- Platform
- Windows
Thanks to some previous communications on mrexcel, I obtained some help generating the subroutine below. The only problem is that it quits working under each of the following conditions:
Does anyone know what the problem is here and how I might fix it?
Sub Get_ABC_value()
'
' Get_ABC_value Macro
'
'
Const TxtToFind = "ABC"
Dim wbS As Workbook: Set wbS = Workbooks("download - source ABC.xls")
Dim wbR As Workbook: Set wbR = Workbooks("results.xlsm")
With wbS.Sheets(1)
If InStr(1, .Range("C7").Value, TxtToFind) > 0 Then
.Range("F7").Copy wbR.Sheets(1).Range("B10")
Else
.Rows(7).Insert
.Range("C7").Value = TxtToFind
With .Range("F7")
.Value = 0
.NumberFormat = "0.0"
.Copy wbR.Sheets(1).Range("B10")
End With
End If
End With
wbS.Save
wbR.Save
wbS.Close False
wbR.Close False
End Sub
- If “ABC” is not contained within Cell C7 it stops at this line of code –
- If “ABC” is contained within Cell C7 it stops at this line of code --
Does anyone know what the problem is here and how I might fix it?
Code:
'
' Get_ABC_value Macro
'
'
Const TxtToFind = "ABC"
Dim wbS As Workbook: Set wbS = Workbooks("download - source ABC.xls")
Dim wbR As Workbook: Set wbR = Workbooks("results.xlsm")
With wbS.Sheets(1)
If InStr(1, .Range("C7").Value, TxtToFind) > 0 Then
.Range("F7").Copy wbR.Sheets(1).Range("B10")
Else
.Rows(7).Insert
.Range("C7").Value = TxtToFind
With .Range("F7")
.Value = 0
.NumberFormat = "0.0"
.Copy wbR.Sheets(1).Range("B10")
End With
End If
End With
wbS.Save
wbR.Save
wbS.Close False
wbR.Close False
End Sub
Code: