VBA to copy/paste from IF formula without creating an empty string

MarkR3003

New Member
Joined
Aug 11, 2019
Messages
23
I am trying to create a macro that will copy the rows in a 24 row table that contain data (but not the rows with only an IF formula giving "" as the FALSE value) and copy them to another workbook in a table after looking for the next blank row. On running the macro for a second time, it considers the blank rows in the receiving table to have an empty string, so pastes the values below the empty / blank rows rather than in the next row below the actual cell values (numeric, general and date)

Grateful if you could check my VBA and amend to ignore the rows with the empty strings ("")

Dim wsCopy As Worksheet
Dim wsDest As Worksheet
Dim lCopyLastRow As Long
Dim lDestLastRow As Long


'Set variables for copy and destination sheets
Set wsCopy = Workbooks("Book1.xlsm").Worksheets("Database Transfer")
Set wsDest = Workbooks("Book2.xlsx").Worksheets("2021")


'1. Find last used row in the copy range based on data in column A
lCopyLastRow = wsCopy.Cells(wsCopy.Rows.Count, "A").End(xlUp).Row


'2. Find first blank row in the destination range based on data in column A
'Offset property moves down 1 row
lDestLastRow = wsDest.Cells(wsDest.Rows.Count, "A").End(xlUp).Offset(1).Row


'3. Copy & Paste Data
wsCopy.Range("A2:V" & lCopyLastRow).Copy
wsDest.Range("A" & Rows.Count).End(xlUp).Offset(1, 0).PasteSpecial xlValues
Selection.Value = Selection.Value
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.

Watch MrExcel Video

Forum statistics

Threads
1,130,112
Messages
5,640,173
Members
417,129
Latest member
geekzilla

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
Top