Link to home
Start Free TrialLog in
Avatar of urthrilled
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
Avatar of SANTABABY
SANTABABY
Flag of United States of America image

I can provide a complete and tested solution of you can provide the code/macro that you are using.
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
Avatar of urthrilled
urthrilled

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?
Oops, I forgot to attach the file....  here it is
Worksheet-Example.xlsm
ASKER CERTIFIED SOLUTION
Avatar of urthrilled
urthrilled

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Just got busy with some day long meetings. Very glad to hear that you have a good handle on the issue. Good luck.
After working with it, the way to work it out became clear