Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Importing a null value into a spreadsheet

Status
Not open for further replies.

wotsit

MIS
Oct 18, 2002
47
0
0
GB
Hi all.

I was wondering if somebody could offer me a bit of advice please as I am a bit stuck and i'm new to macros and vba.

I'm importing data into a spreadsheet using a macro that searches a csv file for specific data and then writing the result back to the spreadsheet. It works great, unless the relevant cell in the csv file is empty. If it is empty, I get a "run-time error '91' object variable or with block variable not set" error message and the macro stops running.
The spreadsheet returns to the Microsoft Visual Basic editor and

"Cells.Find(What:="dysjw3tvms01", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate"

is highlighted in yellow.

Is there a way to get it to write a value in the spreadsheet, such as "n/a" and move down to the next cell?

I've copied a bit of the code below:

Sub Servers()

myfile = Application.GetOpenFilename(FileFilter:="CSV Files (*.csv),*.csv")

If myfile = False Then
' user clicked CANCEL. get out now.
Exit Sub
End If

'---------------------------------------------

Workbooks.Open myfile
myfileName = ActiveWorkbook.Name
Windows("Server Capacity Monitoring.xls").Activate

Windows(myfileName).Activate

Windows("Server Capacity Monitoring.xls").Activate

range("A355").Select
Selection.Copy
Windows(myfileName).Activate
Cells.Find(What:="dysjw3pexc01", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
range("E360").Select
Application.CutCopyMode = False
Selection.Copy
Windows("Server Capacity Monitoring.xls").Activate
Cells(Selection.Row, Columns.Count).End(xlToLeft).Offset(, 1).Select
ActiveSheet.Paste
Application.CutCopyMode = False

range("A356").Select
Selection.Copy
Windows(myfileName).Activate
Cells.Find(What:="dysjw3pexc01", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
range("E361").Select
Application.CutCopyMode = False
Selection.Copy
Windows("Server Capacity Monitoring.xls").Activate
Cells(Selection.Row, Columns.Count).End(xlToLeft).Offset(, 1).Select
ActiveSheet.Paste
Application.CutCopyMode = False


End Sub


Any help would be greatly appreciated.

Thank you
H
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top