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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Formatting Excel Spreadsheet from Access Database - blank lines 1

Status
Not open for further replies.

JoanieB

Programmer
Apr 17, 2001
57
US
What command can I use to insert a blank line based on the value of a cell? Ie: Whenever I encounter a cell with the value "Main" I want to insert a line right before it. Can I even do that? Am familiar with formatting spreadsheets from access database, but am unable to find a way...
 
Dim xlApp, xlBook, xlExcel, xlRange As Object
Set xlApp = CreateObject("Excel.Application")
Set xlBook = GetObject("d:\temp\book3.xls")
Set xlExcel = xlBook.Worksheets(1)
xlApp.Visible = True 'how to unhide xlBook ????
xlExcel.Visible = True
Set xlCells = xlExcel.cells
With xlCells
Set c = .Find(What:="Main")
If Not c Is Nothing Then
firstAddress = xlExcel.range(c.Address).offset(1, 0).Address 'offset(1,0) because we inserted a line before it...
Do
xlExcel.rows(c.row).insert Shift:=xlShiftDown
Set c = .FindNext(c)
Loop While Not c Is Nothing And c.Address <> firstAddress
End If
End With

i hope it works
ide
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top