Solved

Tweak Existing VBA to allow the manual data entry

Posted on 2015-02-19
14
38 Views
Last Modified: 2016-02-10
Hi,

I recently had VBA created to auto populate/fill down data.  I now need to see if it possible to allow the user to overwrite the data that is being populated.  The data is located in column H.  Below is the VBA.  I will also attach the workbook (referencing the Issue Log tab and column h - Ship To)

Private Sub Worksheet_Change(ByVal Target As Range)

With Application
    .EnableEvents = False
    .ScreenUpdating = False
    .DisplayAlerts = False
End With

Dim WS As Worksheet
Dim LastRow As Long
Dim I As Long

'Set ws = ThisWorkbook.Sheets("ISSUE LOG")
Set WS = Sheets("ISSUE LOG")

' get the last row from column A that has a value
LastRow = WS.Range("C" & WS.Rows.Count).End(xlUp).Row
If LastRow < Target.Row Then LastRow = Target.Row

' use the last row to determine how far down to extend the formula
'    ws.Range("A9:A" & lastRow).Formula = "=row()"

If Not Intersect(Target, WS.Columns(3)) Is Nothing Then
    WS.Range("A9:A" & LastRow).Formula = "=IF(C9<>"""",COUNTA($C$9:C9)&""."","""")"
    WS.Range("H9:H" & LastRow).Formula = "=$C$4"
End If

' Look to see if a cell in either columns A through B has been changed
If Not Intersect(Target, Range("A9:H" & LastRow)) Is Nothing Then
    Select Case True
       ' a is blank and b is not blank  ---- a should always be populated,
         ' but on the off chance that it is not set to N2
        Case WS.Cells(Target.Row, 1) = "" And WS.Cells(Target.Row, 2) <> ""
             WS.Cells(Target.Row, 6) = WS.Range("N2")
        ' a is not blank and b is blank set to current date
        Case WS.Cells(Target.Row, 1) <> "" And WS.Cells(Target.Row, 2) = ""
             WS.Cells(Target.Row, 6) = Now
        ' a is not blank and b is not blank set to N2
        Case WS.Cells(Target.Row, 1) <> "" And WS.Cells(Target.Row, 2) <> ""
             WS.Cells(Target.Row, 6) = WS.Range("N2")
        ' a is blank and b is blank set to blank
        Case WS.Cells(Target.Row, 1) = "" And WS.Cells(Target.Row, 2) = ""
             WS.Cells(Target.Row, 6) = ""
    End Select

End If

For I = 9 To LastRow
    If WS.Range("C" & I).Value <> "" Then
        WS.Range("H" & I).Value = WS.Range("C4") & Chr(10) & WS.Range("C5") & Chr(10) & WS.Range("C6") & " " & WS.Range("E6")
        WS.Range("H" & I).RowHeight = 71
    Else
        WS.Range("H" & I).Value = ""
        WS.Range("H" & I).RowHeight = 15
    End If
Next I

With Application
    .EnableEvents = True
    .ScreenUpdating = True
    .DisplayAlerts = True
End With

End Sub

Open in new window

EE-Test-Snag-2015.02.19xls.xls
0
Comment
Question by:jmac001
  • 5
  • 5
  • 4
14 Comments
 
LVL 45

Expert Comment

by:Martin Liss
ID: 40619049
Why can't the user just type over what's there?
0
 

Author Comment

by:jmac001
ID: 40619072
I did try to overwrite, but it reverted back to data that was being pulled down.
0
 
LVL 45

Expert Comment

by:Martin Liss
ID: 40619087
In the Worksheet_Change event change

For I = 9 To LastRow
    If WS.Range("C" & I).Value <> "" Then
        WS.Range("H" & I).Value = WS.Range("C4") & Chr(10) & WS.Range("C5") & Chr(10) & WS.Range("C6") & " " & WS.Range("E6")
        WS.Range("H" & I).RowHeight = 71
    Else
        WS.Range("H" & I).Value = ""
        WS.Range("H" & I).RowHeight = 15
    End If
Next I

Open in new window


to

If WS.Range("C" & LastRow).Value <> "" Then
    WS.Range("H" & LastRow).Value = WS.Range("C4") & Chr(10) & WS.Range("C5") & Chr(10) & WS.Range("C6") & " " & WS.Range("E6")
    WS.Range("H" & LastRow).RowHeight = 71
Else
    WS.Range("H" & LastRow).Value = ""
    WS.Range("H" & LastRow).RowHeight = 15
End If

Open in new window

0
 

Author Comment

by:jmac001
ID: 40619141
Taking out the For/Next does allow for the data to be overwritten, but only the first line (address) is now being copied down and not the contact person and contact details.
0
 
LVL 29

Expert Comment

by:gowflow
ID: 40619165
yes because the routine pulls the data directly each time you activate yes in SNAG LIST and also each time you change anything in SNAG LOG it still go thru this same routine reason why you keep on getting this updated.

Now question:
When do we get the formulas only when SNAG LIST is avctivated ? and if user changes anything in SNAG LOG then you want to take what the user does and not the formulas

Right ??
gowflow
0
 
LVL 45

Expert Comment

by:Martin Liss
ID: 40619188
Are you sure? Did you copy the new code correctly? I ask because this code
For I = 9 To LastRow
    If WS.Range("C" & I).Value <> "" Then
        WS.Range("H" & I).Value = WS.Range("C4") & Chr(10) & WS.Range("C5") & Chr(10) & WS.Range("C6") & " " & WS.Range("E6")
        WS.Range("H" & I).RowHeight = 71
    Else
        WS.Range("H" & I).Value = ""
        WS.Range("H" & I).RowHeight = 15
    End If
Next I

Open in new window

was transferring the address (C4), the person (C5), the phone (C6) and the email (E6) to every row any time a change
was made anyplace on the sheet while the new code
If WS.Range("C" & LastRow).Value <> "" Then
    WS.Range("H" & LastRow).Value = WS.Range("C4") & Chr(10) & WS.Range("C5") & Chr(10) & WS.Range("C6") & " " & WS.Range("E6")
    WS.Range("H" & LastRow).RowHeight = 71
Else
    WS.Range("H" & LastRow).Value = ""
    WS.Range("H" & LastRow).RowHeight = 15
End If

Open in new window

does exactly the same thing except it only affects the last row.
0
 

Author Comment

by:jmac001
ID: 40619267
Gowflow not sure that I fully understand the questions that you are asking,  What formula are you referring to?

Martin I copied the just as you have it above.
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 29

Expert Comment

by:gowflow
ID: 40619575
ok here is my question rephrasing:

I understand that when you put yes in sheet SNAG LIST in Col S it is supposed to put the item in sheet ISSUE LOG at the last row and put also the formula for the address in col H ship to.

Shall we keep this going ?

and when do we prevent the formula of the ship to to being automatically put when the user make his own changes in sheet LIST LOG ???

or  ..?? then clarify.

gowflow
0
 
LVL 45

Expert Comment

by:Martin Liss
ID: 40619649
@jmac001: Please remind me how to get a new row to the Issue Log because I changed one of the "no" to "Yes" on the Snag List and nothing was added to the Issue Log.
0
 

Author Comment

by:jmac001
ID: 40619863
Gowflow, Yes to the first question.   Would it be difficult to have it keep populating and if it needs to be changed the user can go back and update after it has been populated?

Martin - need to have yes in column S and a comment in PM comment section
0
 
LVL 45

Expert Comment

by:Martin Liss
ID: 40619908
It works for me. I just added this.
???
0
 
LVL 29

Accepted Solution

by:
gowflow earned 500 total points
ID: 40620015
ok here it is please try this version.
gowflow
Test-Snag-Template-V03.xls
0
 

Author Closing Comment

by:jmac001
ID: 40622161
Thanks again for your help Gowflow.

Martin decided to give all the points to Gowflow since I couldn't get your solution to work.
0
 
LVL 29

Expert Comment

by:gowflow
ID: 40622712
Tks and glad I could help.
gowflow
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now