urthrilled
asked on
Data Refresh Excel in line with manually entered data?
Attached is an example of the worksheet I need to update.
Columns A&B need to come from the database to ensure all the specifications are being addressed and Columns C thru Z are manually entered.
I have the query that refreshes Columns A & B, keeping the sort and I have the vba (not in the example) to insert an empty row on the change of Category.
What I don't have is when A&B are refreshed, how do I keep the manually entered column data with the appropriate Column A&B information?
Also, is it possible to enter the blank rows and populate the Category name (as in the example?)
Thanks for your help....
Worksheet-Example.xlsm
Columns A&B need to come from the database to ensure all the specifications are being addressed and Columns C thru Z are manually entered.
I have the query that refreshes Columns A & B, keeping the sort and I have the vba (not in the example) to insert an empty row on the change of Category.
What I don't have is when A&B are refreshed, how do I keep the manually entered column data with the appropriate Column A&B information?
Also, is it possible to enter the blank rows and populate the Category name (as in the example?)
Thanks for your help....
Worksheet-Example.xlsm
ASKER
I've attached the workbook with Sheet2, which has the sql data and the macro to insert the blank rows.
I only need the 2 columns, SpecNo and Item_Description, but I included the other information to be used in other ways (i.e. the Category_Description is the Group Name that should go in the blank row)
I see in the Properties of the Connection in Excel it has choices to update and/or insert, but I don't believe that's robust enough for this purpose?
I only need the 2 columns, SpecNo and Item_Description, but I included the other information to be used in other ways (i.e. the Category_Description is the Group Name that should go in the blank row)
I see in the Properties of the Connection in Excel it has choices to update and/or insert, but I don't believe that's robust enough for this purpose?
ASKER
Oops, I forgot to attach the file.... here it is
Worksheet-Example.xlsm
Worksheet-Example.xlsm
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Just got busy with some day long meetings. Very glad to hear that you have a good handle on the issue. Good luck.
ASKER
After working with it, the way to work it out became clear
Here is something to give you an idea. This code has some holes to handle your section breaks and you need to use markers to define section boundaries in your worksheet and enhance the code accordingly.
Option Base 1
'Items array(2,x) contains Item No and Desc
Sub UpdateSpec(Items() As Variant)
Dim i As Integer, j As Integer, cnt As Integer
Dim ws As Worksheet
Set ws = ActiveSheet
i = LBound(Items(1))
cnt = UBound(Items(1))
j = 14
While i <= cnt
If ws.Cells(j, 1) = "" And ws.Cells(j + 1, 1) <> "" Then j = j + 1
If Items(1, i) < ws.Cells(j, 1) Or _
(ws.Cells(j + 1, 1) = "" And (ws.Cells(j + 2, 1) = "" Or Items(1, i) < ws.Cells(j + 2, 1))) Then
ws.Rows(j).Insert Shift:=xlDown
ws.Cells(j, 1) = Items(1, i)
ws.Cells(j, 2) = Items(2, i)
i = i + 1
j = j + 1
ElseIf Items(1, i) < ws.Cells(j, 1) Then
j = j + 1
i = i + 1
Else
ws.Rows(j).Delete
End If
Wend
End Sub