modification needed - stumped!

erutherford

Active Member
Joined
Dec 19, 2016
Messages
379
The code takes entry information ("entries") and prefills another worksheet ("Final_Wash") with that data. Works flawless.
I would like to modify the code so that it looks at the "entries" worksheet, column I and only selects those records with a "W".
Usually pretty good at modifying existing code, but stumped on this one. My guess is the modification is in the "create array from range"



Code:
<code>
Private Sub CommandButton8_Click() 'Wash Print Final
Dim EntriesRange As Range, BasicRange As Range
    Dim PrintCell As Range, cell As Range
    Dim Data As Variant
    Dim i As Integer
    Dim msg
    
       
            
   msg = MsgBox("Confirm Print all records?", vbYesNo, "Confirm")
        If msg = vbYes Then
    With ThisWorkbook
'basic sheet data entry range
        Set BasicRange = .Worksheets("Final_Wash").Range("B2,D2,E2,B5,C5,D5,E5,G5,J5")
        With .Worksheets("Entries")
            Set EntriesRange = .Range(.Range("A3"), .Range("A" & .Rows.Count).End(xlUp))
        End With
    End With
    
    For Each cell In EntriesRange.Cells
'create array from range
        Data = Application.Transpose(cell.Resize(1, 9).Value2)
        i = 1
'array elements to non-contiguous range
        For Each PrintCell In BasicRange.Cells
            PrintCell.Value = Data(i, 1)
'increment to next array element
            i = i + 1
        Next PrintCell
        
'print out record
      BasicRange.Parent.PrintPreview
    Next cell
    ElseIf msg = vbNo Then

            End If
    Exit Sub
End Sub
</code>
 
Last edited by a moderator:

Some videos you may like

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
42,882
Office Version
365
Platform
Windows
How about
Code:
    For Each cell In EntriesRange.Cells
      If cell.Offset(, 8).Value = "W" Then
   'create array from range
           Data = Application.Transpose(cell.Resize(1, 9).Value2)
           i = 1
   'array elements to non-contiguous range
           For Each PrintCell In BasicRange.Cells
               PrintCell.Value = Data(i, 1)
   'increment to next array element
               i = i + 1
           Next PrintCell
           
   'print out record
         BasicRange.Parent.PrintPreview
      End If
    Next cell
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
42,882
Office Version
365
Platform
Windows
How about
Code:
Private Sub CommandButton8_Click() 'Wash Print Final
Dim EntriesRange As Range, BasicRange As Range
    Dim PrintCell As Range, cell As Range
    Dim Data As Variant
    Dim i As Integer
    Dim msg
    
       
            
   msg = MsgBox("Confirm Print all records?", vbYesNo, "Confirm")
        If msg = vbYes Then
    With ThisWorkbook
'basic sheet data entry range
        Set BasicRange = .Worksheets("Final_Wash").Range("B2,D2,E2,B5,C5,D5,E5,G5,J5")
        With .Worksheets("Entries")
            Set EntriesRange = .Range(.Range("A3"), .Range("A" & .Rows.Count).End(xlUp))
        End With
    End With
    
   For Each cell In EntriesRange.Cells
      If cell.Offset(, 8).Value = "W" Then
   'create array from range
           Data = Application.Transpose(cell.Resize(1, 9).Value2)
           i = 1
   'array elements to non-contiguous range
           For Each PrintCell In BasicRange.Cells
               PrintCell.Value = Data(i, 1)
   'increment to next array element
               i = i + 1
           Next PrintCell
           
   'print out record
         BasicRange.Parent.PrintPreview
      End If
    Next cell
    End If
End Sub
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
42,882
Office Version
365
Platform
Windows
You're welcome & thanks for the feedback
 

Watch MrExcel Video

Forum statistics

Threads
1,102,736
Messages
5,488,566
Members
407,646
Latest member
utl1095

This Week's Hot Topics

  • Timer in VBA - Stop, Start, Pause and Reset
    [CODE=vba][/CODE] Option Explicit Dim CmdStop As Boolean Dim Paused As Boolean Dim Start Dim TimerValue As Date Dim pausedTime As Date Sub...
  • how to updates multiple rows in muliselect listbox
    Hello everyone. I need help with below code. code is only chaning 1st row in mulitiselect list box. i know issue with code...
  • Delete Row from Table
    I am trying to delete a row from a table using VBA using a named range to find what I need to delete. My Range is finding the right cell. In the...
  • Assigning to a variable
    I have a for each block where I want to assign the value in column 5 of the found row to the variable Serv. [CODE=vba] For Each ws In...
  • Way to verify information
    Hi All, I don't know what to call this formula, and therefore can't search. I have a spreadsheet with information I want to reference...
  • Active Cell Address – Inactive Sheet
    How to use VBA to get the cell address of the active cell in an inactive worksheet and then place that cell address in a location on the current...
Top