VBA to copy non blank cells to new sheet

patsism

New Member
Joined
Aug 12, 2015
Messages
4
I have two sheets "input sheet" & "sheet3", I want to copy a dynamic range (range dependent on input in I3:P20) from "input sheet" A3:G20 to next blank row on "sheet3". Because there is a formula in cells A3:G20 when I select the current region it picks up all the cells not just the ones with visible data and copies it all. On "sheet3" it appears the cells are blank but when copy/paste repeated it starts at the end of the 'blank' cells. I a have tried what I can find as far as Paste Special but no luck so far. Code is below and I tried to add a mini sheet (not sure if it worked):

Sheets("input sheet").Select
Range("A3").Select
Selection.CurrentRegion.Select
Selection.Copy
Sheets("Sheet3").Select
Selection.End(xlDown).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=True, Transpose:=False
ActiveWindow.SmallScroll Down:=15
Application.CutCopyMode = False
Range("a1").Select

Input Test.xlsm
ABCDEFGHIJKLMNOPQ
1-290321-01-AMain Description290321-01-A3 digits
2Batch Size1.00Actual UsedLot #
3-290321-01-AMain DescriptionData Field 11145680g428531 820Data Field 11145680g680428531 820
4-290321-01-AMain DescriptionData Field 211466lAL 04Data Field 211466l6AL 04
5-290321-01-AMain DescriptionData Field 31147100lbs2280615Data Field 31147100lbs1002280615
6-290321-01-AMain DescriptionData Field 4114850g2280022Data Field 4114850g502280022
7-290321-01-AMain DescriptionData Field 5114930g267025Data Field 5114930g30267025
8       
9       
10       
11       
12       
13       
14       
Input sheet
Cell Formulas
RangeFormula
A1A1=CONCATENATE(M1,"-",L1)
A3:A14A3=IF(I3<>"",$A$1,"")
B3:B14B3=IF(I3<>"",$I$1,"")
C3:C14C3=IF(I3<>"",$I3,"")
D3:D5D3=IF(I$3<>"",L3,"")
E3:E14E3=IF($I3<>"",O3,"")
D6:D14,F3:F14F3=IF($I3<>"",N3,"")
G3:G14G3=IF($I3<>"",P3,"")
Named Ranges
NameRefers ToCells
'Input sheet'!Print_Area='Input sheet'!$I$1:$Q$20B3:B14
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Hi & welcome to MrExcel.
How about
VBA Code:
Sub patsism()
   With Sheets("input sheet")
      With .Range("A3:G" & .Range("I" & Rows.Count).End(xlUp).Row)
         Sheets("Sheet3").Range("A" & Rows.Count).End(xlUp).Offset(1).Resize(.Rows.Count, 7).Value = .Value
      End With
   End With
End Sub
 
Upvote 0
Solution
Hi & welcome to MrExcel.
How about
VBA Code:
Sub patsism()
   With Sheets("input sheet")
      With .Range("A3:G" & .Range("I" & Rows.Count).End(xlUp).Row)
         Sheets("Sheet3").Range("A" & Rows.Count).End(xlUp).Offset(1).Resize(.Rows.Count, 7).Value = .Value
      End With
   End With
End Sub
Thanks, that worked. Obviously, I'm new to VBA - almost seems to simple:)
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0
Same process, different workbook. Code runs ok until I try and add a paste special. I am not familiar with With/End With so don't know if that is causing the problem.
This is the code I have that works (except for formulas paste over as well) I removed the With/End With and .value
Range("ProductDump").Copy Sheets("MasterDumpProduction").Range("A" & Rows.Count).End(xlUp).Offset(1)
 
Upvote 0
Same process, different workbook. Code runs ok until I try and add a paste special. I am not familiar with With/End With so don't know if that is causing the problem.
This is the code I have that works (except for formulas paste over as well) I removed the With/End With and .value
Range("ProductDump").Copy Sheets("MasterDumpProduction").Range("A" & Rows.Count).End(xlUp).Offset(1)

Answered my own question with a little more skulking:) It seems the I had to include the With/End With portion
With Sheets("input sheet")
With .Range("ProductDump").Copy
Sheets("MasterDumpProduction").Range("A" & Rows.Count).End(xlUp).Offset(1).PasteSpecial xlPasteValues
End With
End With
 
Upvote 0
Glad you sorted it & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,968
Messages
6,122,506
Members
449,089
Latest member
RandomExceller01

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top