Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 49
  • Last Modified:

Tweak Existing VBA to allow the manual data entry

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
jmac001
Asked:
jmac001
  • 5
  • 5
  • 4
1 Solution
 
Martin LissRetired ProgrammerCommented:
Why can't the user just type over what's there?
0
 
jmac001Author Commented:
I did try to overwrite, but it reverted back to data that was being pulled down.
0
 
Martin LissRetired ProgrammerCommented:
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
jmac001Author Commented:
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
 
gowflowCommented:
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
 
Martin LissRetired ProgrammerCommented:
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
 
jmac001Author Commented:
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
 
gowflowCommented:
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
 
Martin LissRetired ProgrammerCommented:
@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
 
jmac001Author Commented:
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
 
Martin LissRetired ProgrammerCommented:
It works for me. I just added this.
???
0
 
gowflowCommented:
ok here it is please try this version.
gowflow
Test-Snag-Template-V03.xls
0
 
jmac001Author Commented:
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
 
gowflowCommented:
Tks and glad I could help.
gowflow
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

  • 5
  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now