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

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
42,537
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,537
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,537
Office Version
365
Platform
Windows
You're welcome & thanks for the feedback
 

Watch MrExcel Video

Forum statistics

Threads
1,102,134
Messages
5,484,932
Members
407,474
Latest member
Pam Sander

This Week's Hot Topics

  • Finding issue in If elseif else with For each Loop
    Finding issue in If elseif else with For each Loop I have tried this below code but i'm getting in Y column filled with W005. Colud you please...
  • MsgBox Error
    Hi Guys, I have the below error show up when i try and run my macro in File1 but works fine if i copy and paste the same code into file2. [ATTACH...
  • CELL FORMAT - IF CONDITION
    My Cell Format is [B]""0.00" Cr". [/B]But in the cell, it is showing 123.00 for editing. (123 is entry figure). (Data imported from other...
  • Show numbers nearly the same
    Is this possible. I have a number that can change very time eg 0.00001234 Then I have a lot of numbers 0.0000001, 0.0000002, 0.00000004...
  • Please i need your help to create formula
    I need a formula in cell B8 to do this >>if b1=1 then multiply ( cell b8) by 10% ,if b1=2 multiply by 20%,if=3 multiply by 30%. Thank you in...
  • Got error while adding column and filter
    Got error while adding column and filter In column Z has some like "Success" and "Error". I want to add column in AA if the Z cell value is...
Top