Can you please help me to adjust this VBA code as required. After the line 'If…
- User
Can you please help me to adjust this VBA code as required. After the line 'If ActiveCell.Column = 9 And ActiveCell.Offset(0, -1).Value <> "" Then ' column I "P REQUEST #" & "H SPECIAL NOTES"' I want the values of the row from column A to J to be copied to column T from T2 to T11 downwards
Dim rowNum As Integer Dim headerCell As Range Dim rowcell As Range Dim outputString As String rowNum = ActiveCell.row Set rng = Range("A" & rowNum & ":K" & rowNum) If Target.CountLarge > 1 Then Exit Sub 'only one cell at a time On Error Resume Next If Not Intersect(ActiveCell, Range("I2:I2001")) Is Nothing And Target.Value = "" Then Exit Sub Else If ActiveCell.Column = 9 And ActiveCell.Offset(0, -1).Value <> "" Then ' column I "P REQUEST #" & "H SPECIAL NOTES"
Dim wdApp As Object Dim wdDoc As Object Dim WsdShell As Object Set wdApp = CreateObject("Word.Application") Dim filePath As String filePath = ThisWorkbook.Path & "\zzzz ServProvDocs\PurchaseRequest.docm" Set wdDoc = wdApp.Documents.Open(filePath) wdApp.Visible = True
Set WsdShell = CreateObject("WScript.Shell") WsdShell.AppActivate wdApp.Caption
Application.Wait (Now + TimeValue("0:00:02"))
'Application.EnableEvents = False 'outputString = "" '' Loop through headers and row values in parallel 'For Each headerCell In Range("A1:K1") 'outputString = outputString & headerCell.Value & vbCrLf 'outputString = outputString & rng.Cells(1, headerCell.Column).Value & vbCrLf 'Next headerCell 'Shell "notepad.exe", vbNormalFocus 'Application.Wait Now + TimeValue("00:00:01") 'SendKeys outputString Cancel = True ' Prevents entering edit mode on double-click Application.CutCopyMode = False Application.EnableEvents = True End IfCancel = True ' Prevents entering edit mode on double-click End If Cancel = True ' Prevents entering edit mode on double-click
End Sub - Assistant
Here's the modified code:
Dim rowNum As Integer Dim headerCell As Range Dim rowcell As Range Dim outputString As String rowNum = ActiveCell.Row Set rng = Range("A" & rowNum & ":K" & rowNum) If Target.CountLarge > 1 Then Exit Sub 'only one cell at a time On Error Resume Next If Not Intersect(ActiveCell, Range("I2:I2001")) Is Nothing And Target.Value = "" Then Exit Sub Else If ActiveCell.Column = 9 And ActiveCell.Offset(0, -1).Value <> "" Then ' column I "P REQUEST #" & "H SPECIAL NOTES" Dim wdApp As Object Dim wdDoc As Object Dim WsdShell As Object Set wdApp = CreateObject("Word.Application") Dim filePath As String filePath = ThisWorkbook.Path & "\zzzz ServProvDocs\PurchaseRequest.docm" Set wdDoc = wdApp.Documents.Open(filePath) wdApp.Visible = True Set WsdShell = CreateObject("WScript.Shell") WsdShell.AppActivate wdApp.Caption Application.Wait (Now + TimeValue("0:00:02")) ' Copy values from column A to J to column T Dim i As Integer For i = 1 To 10 Range("T" & (i + 1)).Value = rng.Cells(1, i).Value Next i Cancel = True ' Prevents entering edit mode on double-click Application.CutCopyMode = False Application.EnableEvents = True End If End If Cancel = True ' Prevents entering edit mode on double-click - User
I need the values to be copied to T2:T11 before the word document opens
- Assistant
To copy the values to column T (T2 to T11) before opening the Word document, you can modify the code as follows:
Dim rowNum As Integer Dim headerCell As Range Dim rowcell As Range Dim outputString As String rowNum = ActiveCell.Row Set rng = Range("A" & rowNum & ":K" & rowNum) If Target.CountLarge > 1 Then Exit Sub 'only one cell at a time On Error Resume Next If Not Intersect(ActiveCell, Range("I2:I2001")) Is Nothing And Target.Value = "" Then Exit Sub Else If ActiveCell.Column = 9 And ActiveCell.Offset(0, -1).Value <> "" Then ' column I "P REQUEST #" & "H SPECIAL NOTES" Dim wdApp As Object Dim wdDoc As Object Dim WsdShell As Object Set wdApp = CreateObject("Word.Application") Dim filePath As String filePath = ThisWorkbook.Path & "\zzzz ServProvDocs\PurchaseRequest.docm" ' Copy values from column A to J to column T Dim i As Integer For i = 1 To 10 Range("T" & (i + 1)).Value = rng.Cells(1, i).Value Next i Set wdDoc = wdApp.Documents.Open(filePath) wdApp.Visible = True Set WsdShell = CreateObject("WScript.Shell") WsdShell.AppActivate wdApp.Caption Application.Wait (Now + TimeValue("0:00:02")) Cancel = True ' Prevents entering edit mode on double-click Application.CutCopyMode = False Application.EnableEvents = True End If End If Cancel = True ' Prevents entering edit mode on double-click